How can I use a local image as a base image with a docker file?

I am working on a docker file. I just realized that I use FROM with indexed images all the time.

So interesting:

  • How can I use one of my local (custom) images as my base image ( FROM ) without pushing it to the index?
+42
docker
Dec 09 '13 at 21:30
source share
3 answers

You can use it without doing anything special. If you have a local image called blah , you can do FROM blah . If you do FROM blah in your Docker file but donโ€™t have a local image named blah , then Docker will try to extract it from the registry.

In other words, if the Docker file does FROM ubuntu , but you have a local image called ubuntu different from the official one, your image will override it.

+51
Dec 10 '13 at 17:50
source share

Checked: It works well in docker 1.7.0.

Btw, do not specify --pull=true when running the docker build :

if you want use the local image as the base image, please without the option --pull=true, --pull=true will always attempt to pull a newer version of the image.

https://github.com/docker/docker/issues/14943

+9
Jul 24. '15 at 12:03
source share

I have no reputation to add a comment (@defreitas) by adding it as an answer. You may have characters in your images. Suppose you have a local image (and not a local registry) named centos-base-image with the tag 7.3.1611.

 docker version Client: Version: 1.12.6 API version: 1.24 Package version: docker-common-1.12.6-16.el7.centos.x86_64 Go version: go1.7.4 Server: Version: 1.12.6 API version: 1.24 Package version: docker-common-1.12.6-16.el7.centos.x86_64 Go version: go1.7.4 docker images REPOSITORY TAG centos-base-image 7.3.1611 

Dockerfile

 FROM centos-base-image:7.3.1611 RUN yum -y install epel-release libaio bc flex 

Result

 Sending build context to Docker daemon 315.9 MB Step 1 : FROM centos-base-image:7.3.1611 ---> c4d84e86782e Step 2 : RUN yum -y install epel-release libaio bc flex ---> Running in 36d8abd0dad9 ... 

In the above example, FROM retrieves the local image, you can provide additional instructions for retrieving the image from your custom registry (for example, FROM localhost:5000/my-image:with.tag ). See https://docs.docker.com/engine/reference/commandline/pull/#pull-from-a-different-registry and https://docs.docker.com/registry/#tldr

Finally, if your image will not be allowed when providing the name, try adding a tag to the image when creating it.

 https://docs.docker.com/engine/reference/commandline/commit/ 

This form describes a similar problem.

 https://github.com/moby/moby/issues/8975 

Omitting a specific tag, the docker will search for an image with "last" tags, so either create an image using the last tag, or change your

Added the above links in the form of code blocks, because I do not have enough messages to post more than two links ...;)

+3
Apr 30 '17 at 16:12
source share



All Articles