Modifying Docker Registry based on environment

  docker, dockerfile

My local development environment is behind a corporate proxy, with our own Docker registry, etc. However, we deploy on public infrastructure, meaning we can’t access the corporate registries, and so have to pull from a public one (eg DockerHub).

Is there any way (eg via environment variables) for me to configure Docker to pull from a private registry when developing locally, and from a public registry when it goes through our CI/CD pipeline?

For example, let’s say we’re deploying a Node.JS application – locally, I would want the FROM node:16 line to get interpreted as FROM corporate.proxy/node:16.

There are a couple methods that would probably work – having two separate Dockerfiles, eg and, or wrapping it in some sort of script that will take care of making the change. I’m looking for a way to do it via Docker’s configuration, if it’s possible at all.

Source: Docker Questions