Can you tell me why a directory has not been created in the container?
Here is the DockerFile
FROM node:16.13-alpine AS base
WORKDIR /usr/app/test/
RUN npm config set unsafe-perm true
COPY ./test/ .
FROM nginx:1.20-alpine
LABEL version="1.0"
COPY nginx.conf /etc/nginx/nginx.conf
WORKDIR /usr/share/nginx/html
COPY ./test/dist/my-app/ .
I created an image, launched it, I go into it, but there is no directory there
/usr/app/test
There are no errors when creating an image:
Step 1/9 : FROM node:16.13-alpine AS base
---> 710c8aa630d5
Step 2/9 : WORKDIR /usr/app/test/
---> Running in dbe3994e667a
Removing intermediate container dbe3994e667a
---> 54b36120290d
Step 3/9 : RUN npm config set unsafe-perm true
---> Running in e301f90c084f
Removing intermediate container e301f90c084f
---> ca6dc8541ba5
Step 4/9 : COPY ./test/ .
---> e00bf919a630
Here's what's in the container:
CodePudding user response:
Your Dockerfile is defining a multi-stage build, and what you are seeing is expected behavior.
Everything before the second FROM
, so in this case FROM nginx:1.20-alpine
, is discarded in the final image unless it's copied over.
If you want the first WORKDIR
to persist in the final image, you need to explicitly copy over:
FROM node:16.13-alpine AS base
WORKDIR /usr/app/test/
FROM nginx:1.20-alpine
COPY --from=0 /usr/app/test /usr/app/test
WORKDIR /usr/share/nginx/html