diff --git a/src/content/docs/workers/wrangler/commands.mdx b/src/content/docs/workers/wrangler/commands.mdx index 4ce9bf902d6fe93..df2cce705db7449 100644 --- a/src/content/docs/workers/wrangler/commands.mdx +++ b/src/content/docs/workers/wrangler/commands.mdx @@ -669,6 +669,36 @@ Leave the login flow active. Open a second terminal session. In that second term curl ``` +### Use `wrangler login` in a container + +The Cloudflare OAuth provider will always redirect to a callback server at `localhost:8976`. If you are running Wrangler inside a container, this server might not be accessible from your host machine's browser - even after authorizing the connection, your login command will hang. + +You must configure your container to map port `8976` on your host machine to the Wrangler OAuth callback server's port (`8976` by default). + +For example, if you are running Wrangler in a Docker container: + +```sh +docker run -p 8976:8976 +``` + +And when you run `npx wrangler login` inside your container, set the callback host to listen on all network interfaces: + +```sh +npx wrangler login --callback-host=0.0.0.0 +``` + +Now when the browser redirects to `localhost:8976`, the request will be forwarded to Wrangler running inside the container on `0.0.0.0:8976`. + +If you need to use a different port inside the container, use `--callback-port` as well and adjust your port mapping accordingly, for example: + +```sh +# When starting your container +docker run -p 8976:9000 + +# Inside the container +npx wrangler login --callback-host=0.0.0.0 --callback-port=9000 +``` + --- ## `logout`