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

Viewed 164999

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?
8 Answers

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.

Remember to put not only the tag but also the repository in which that tag is, this way:

docker images
REPOSITORY                                TAG                       IMAGE ID            CREATED             SIZE
elixir                                    1.7-centos7_3             e15e6bf57262        20 hours ago        925MB

You should reference it this way:

elixir:1.7-centos7_3

For users with M1 chips, problem can be arisen when platform differs of local image differs from target Dockerfile. In my case, I've built base image with M1 support and then tried to use command FROM in image that was building with platform linux/amd64

Our /etc/docker/daemon.json had a line declaring

"disable-legacy-registry" : true,

With that line in, the local registry was refusing access.
With it removed, it's working.

I just ran into this on an M1 Mac with engine version 20.10.14. It wasn't obvious from docker build --help, but passing --pull=false worked for me.

Related