Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

WORKDIR does not create a directory

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

/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:

enter image description here

>Solution :

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
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading