I have two containers for two separate sites and one container for nginx. All I want to do is to copy build files of each site to /usr/share/nginx/html/<site_name>/
in nginx container. I want to keep separate Dockerfile
for each site and have named site containers as builder_one
and builder_two
to copy files from these in nginx Dockerfile
:
FROM nginx:latest
COPY ./conf.d/ /etc/nginx/conf.d/
RUN mkdir /usr/share/nginx/html/site_one
RUN mkdir /usr/share/nginx/html/site_two
COPY --from=builder_one /usr/src/site_one/build/ /usr/share/nginx/html/site_one/
COPY --from=builder_two /usr/src/site_two/build/ /usr/share/nginx/html/site_two/
How ever, I get an error:
------
> [dockernginx-nginx] FROM docker.io/library/builder_two:latest:
------
failed to solve: failed to load cache key: pull access denied, repository does not exist or may require authorization: server message: insufficient_scope: authorization failed
It fails when running COPY
command as it tries to pull the container from Docker registry. Why? How do I copy files to nginx container correctly?
Maybe there is another way I could achieve this?
2
Answers
You need to declare the image names from your previous builds in the same docker file.
In your example:
You clarify in comments that you have three separate Dockerfiles, and start the first two with
FROM base-image AS builder_one
syntax. That alias syntax only works within a single Dockerfile; the aliases aren’t persisted as part of the image and can’t be referenced from other Dockerfiles.COPY --from
can also take a full image name. For the specific setup you describe, you need to build each of the component images with a known tagand then in the final Dockerfile, use those image names
The component images don’t need
FROM ... AS
syntax, and you can generally remove anAS alias
part of a Dockerfile’s final stage’sFROM
line.