platform docker

Inside a Docker container, the authentication callback to localhost used by the standard clasp login command may not be reachable from the browser on the host. This article explains how to log in with --network host so the container shares the host network.

Thumbnail

Environment

  • OS: WSL2 (this is a Linux-oriented procedure)
  • Node.js (Docker container): node:26-alpine
  • clasp 3.3.0

On Docker Desktop for Windows / Mac, --network host may not work as expected.

Use normal clasp login with –network host

If you start the container on the host network, the post-auth localhost callback reaches clasp inside the container.

Create the credentials file on the host first (once):

touch ~/.clasprc.json

Start the container:

docker run -it --rm \
  --network host \
  -v "$(pwd):/app" \
  -v "$HOME/.clasprc.json:/root/.clasprc.json" \
  -w /app \
  node:26-alpine sh

Inside the container, install the project dependencies (including clasp 3.3.0 from package.json) and log in:

npm ci
npx clasp login

Open the authentication URL shown in the terminal in a browser on the host, and grant access with your Google account. On success, credentials are saved to ~/.clasprc.json (the file mounted from the host).

You can then run npx clasp push and similar commands in the same container.

On later runs, credentials remain in the mounted ~/.clasprc.json, so you usually do not need clasp login again. Re-login only when the token expires or you switch Google accounts.

Do not use –no-localhost

Older guides sometimes recommended npx clasp login --no-localhost (paste the auth result into the terminal) for Docker. However, Google has deprecated and blocked the Out-of-Band (OOB) OAuth flow, so this method usually fails now.

Reference

This article was generated by Cursor from a Cursor session log.

Related articles