Pull docker images from a private repository during docker build?
Solution 1
I was facing the same issue in 2019. I solved this using arguments (ARG).
https://docs.docker.com/engine/reference/builder/#understand-how-arg-and-from-interact
Arguments allow you to set optional parameters (with defaults) that can be used in your FROM line.
Dockerfile-project-dev
ARG REPO_LOCATION=privaterepo.company.net/
ARG BASE_VERSION=latest
FROM ${REPO_LOCATION}project/base:${BASE_VERSION}
...
For my use-case I normally want to pull from the private repo, but if I'm working on the Dockerfiles I may want to be able to build from an image on my own machine, without having to modify the FROM line in my Dockerfile. To tell Docker to search my local machine for the image at build time I would do this:
docker build -t project/dev:latest -f ./Dockerfile-project-dev --build-arg REPO_LOCATION='' .
Solution 2
The image name should include the FQDN of the registry host.
So if you want to FROM <some private image>
you must specifiy it as FROM registry_host:5000/foo/bar
In the future this won't be a requirement, but unfortunately for now it is.
Solution 3
The docker folks generally want to ensure that if you run docker pull foo/bar
you'll get the same thing (i.e., the foo/bar
image from Docker Hub) regardless of your local environment.
This means that there are no options available to have Docker use anything else without an explicit hostname/port.
![Julio Guerra](https://i.stack.imgur.com/M8neB.jpg?s=256&g=1)
Julio Guerra
Software Engineer http://fr.linkedin.com/in/guerrajulio
Updated on October 10, 2020Comments
-
Julio Guerra over 3 years
Is there any way of pulling images from a private registry during a
docker build
instead of docker hub?I deployed a private registry and I would like to be able to avoid naming its specific
ip:port
in the Dockerfile'sFROM
instruction. I was expecting adocker build
option or a docker environment variable to change the default registry.