How can I use a local image as the base image with a dockerfile?

I'm working on a dockerfile. I just realised that I've been using FROM with indexed images all along.

So I wonder:

  • How can I use one of my local (custom) images as my base (FROM) image without pushing it to the index?

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 Dockerfile, but don't have a local image called blah, then Docker will try to pull it from the registry.

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


Verified: it works well in Docker 1.7.0.

Don't specify --pull=true when running the docker build command

From this thread on reference locally-built image using FROM at dockerfile:

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


For anyone who faces this issue in the future, where you have the image in your local but docker build still tries to pull the image from docker hub, the problem might be that the architecture types are different.

Trying to pull from docker.io even though image exists

You can check the architecture of the image using

docker inspect --format='{{.Os}}/{{.Architecture}}' IMAGE_NAME

Now in your Dockerfile change FROM IMAGE_NAME to something like FROM --platform=linux/amd64 IMAGE_NAME and docker would now use the local image.