Using a mirrored image
If you've mirrored an image to your local repository then you can just use that instead of the public reference.
For example, if you mirrored the golang:alpine
image to docker.example.com
then just reference it as docker.example.com/library/golang:alpine
How to use both public & mirrored images in the same Dockerfile
If, like myself, you have a lot of Open Sourced projects you want to have a single Dockerfile which anyone can run without having access to, or even knowledge of your private repository.
The solution to this is to use build arguments.
Here's an example from one of my Dockerfiles (actually from the Dockerfile that builds this actual site):
1ARG prefix
2FROM ${prefix}golang:alpine AS build
Here we have a build argument prefix
and in the FROM line we've prefixed the source image name,
so where we want to use golang:alpine
we've defined it as ${prefix}golang:alpine
.
When someone runs the build, prefix
defaults to "" so they get the public golang:alpine
image.
However, locally you can run docker build passing the prefix to your local repository:
1docker build --build-arg prefix=docker.example.com/library/ -t myproject:latest .
As you've now set the prefix to point to your local repository then the build will now use the local
docker.example.com/library/golang:alpine
image instead of the public one.