Docker Community Forums

Share and learn in the Docker community.

Not finding local unprefixed Docker image in the local cache

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

Docker is installed and running. Repeating the command only results in the same error.

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 …

$ docker --version
Docker version 20.10.7, build f0df350

$ 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 before the Summer this worked perfectly fine, but that was on a Linux box, so could this be down to a new Docker version or some bug relating to the M1 chip?

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

For reference, this works fine on another (WSL) machine with the exact same Docker version. Instead of failing, it finds the image in the cache:

$ 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

It seems like this is a known issue with arm software using intel containers: Apple m1 - can't build on a local 'base' image which is qemu based · Issue #5419 · docker/for-mac · GitHub

This fix seems to be to force all your images to run under emulation using QEMU:

FROM --platform=linux/amd64 my-base-image
1 Like