Unable to find (local) image in cache when building derived image

Viewed 701

Error on new mac

When building a Docker image on a totally fresh new Macbook (M1 Apple chip) I get this:

$ docker build -f Dockerfile-local-dev .
[+] Building 1.4s (3/3) FINISHED
 => [internal] load build definition from Dockerfile-local-dev                                                                                            0.0s
 => => transferring dockerfile: 47B                                                                                                                       0.0s
 => [internal] load .dockerignore                                                                                                                         0.0s
 => => transferring context: 2B                                                                                                                           0.0s
 => ERROR [internal] load metadata for docker.io/library/nicecorp-empty-db:latest                                                                           1.3s
------
 > [internal] load metadata for docker.io/library/nicecorp-empty-db:latest:
------
failed to solve with frontend dockerfile.v0: failed to create LLB definition: pull access denied, repository does not exist or may require authorization: server message: insufficient_scope: authorization failed

This apparently has something to do with pull policies and such, but it should just find a local image and use that, not try and pull it off the global Docker registry ...

No error on Ubuntu and other macs!

The weird thing is that this works on all my other machines, running the same docker build (20.10.7, build f0df350)!

$ docker build -f Dockerfile-local-dev .
[+] Building 0.1s (8/8) FINISHED
 => [internal] load build definition from Dockerfile-local-dev                                                                                                                                     0.0s
 => => transferring dockerfile: 48B                                                                                                                                                                0.0s
 => [internal] load .dockerignore                                                                                                                                                                  0.0s
 => => transferring context: 2B                                                                                                                                                                    0.0s
 => [internal] load metadata for docker.io/library/nicecorp-empty-db:latest                                                                                                                          0.0s
 => [1/4] FROM docker.io/library/nicecorp-empty-db                                                                                                                                                   0.0s
 => CACHED [2/4] RUN /etc/init.d/postgresql start &&     psql --command "CREATE DATABASE nicecorpdb_test_template OWNER nicecorpadmin;" &&     psql --command "ALTER USER nicecorpadmin SUPERUSER;"      0.0s
 => CACHED [3/4] RUN echo "host all all samenet password" >> /etc/postgresql/12/main/pg_hba.conf                                                                                                   0.0s
 => CACHED [4/4] RUN echo "max_connections = 1000" >> /etc/postgresql/12/main/postgresql.conf                                                                                                      0.0s
 => exporting to image                                                                                                                                                                             0.0s
 => => exporting layers                                                                                                                                                                            0.0s
 => => writing image sha256:06b87e72ee838bef04380d9668b4dca49efede61cf0888289a58544d1019ca1c
$ docker --version
Docker version 20.10.7, build f0df350

Image is present in the local cache

$ docker image ls
REPOSITORY        TAG       IMAGE ID       CREATED          SIZE
nicecorp-empty-db   latest    99c3d1659d80   20 minutes ago   393MB

When doing this exact thing on the same code and Dockerfile on a Linux box (actually WSL2) this worked perfectly fine. Same with my Intel iMac, so could this be down to some bug relating to the M1 chip and the Docker version?

The Dockerfile-local-dev file:

$ cat Dockerfile-local-dev
# Most definitely not to be used in production!
FROM nicecorp-empty-db

MAINTAINER ACME <devs@ACME.com>

# Allow nicecorpadmin user to create and drop databases (used for test runs)
RUN /etc/init.d/postgresql start && \
    psql --command "CREATE DATABASE nicecorpdb_test_template OWNER nicecorpadmin;" && \
    psql --command "ALTER USER nicecorpadmin SUPERUSER;"

# Allow all users to connect to all databases (used for test runs to allow ad-hoc databases)
RUN echo "host all all samenet password" >> /etc/postgresql/12/main/pg_hba.conf
RUN echo "max_connections = 1000" >> /etc/postgresql/12/main/postgresql.conf

The image is found when running

Seems to find the local image jsut fine when I try to run it:

$ docker run nimble-empty-db:latest
 * Starting PostgreSQL 12 database server
   ...done.
2021-08-01 18:31:31.765 CEST [22] LOG:  starting PostgreSQL 12.7 (Ubuntu 12.7-1.pgdg20.04+1) on aarch64-unknown-linux-gnu, compiled by gcc (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0, 64-bit
2021-08-01 18:31:31.765 CEST [22] LOG:  listening on IPv4 address "0.0.0.0", port 5432
1 Answers

I faced a similar issue and found the advise in this git issue to be of use: https://github.com/docker/for-mac/issues/5419

Adding --platform=linux/amd64 to my FROM commands fixed the issue for me, so in your case it would be:

FROM --platform=linux/amd64 nicecorp-empty-db

Alternatively one could set export DOCKER_DEFAULT_PLATFORM=linux/amd64 to avoid changing the actual files. In fact, for the Ubuntu image in question, it does exist for an ARM platform, so one can also set it as linux/arm64.

Related