skip to Main Content

I’ve been building nodejs applications and wanted to investigate projects inside a Docker container.
But when I check the running container via bin/bash I cannot find /app directory in a container

While building image no errors are being displayed

This is my docker image file

FROM node:15.7.0 as build-stage
WORKDIR /app
COPY package*.json /app/
RUN npm install
COPY ./ /app/
ARG configuration=production
RUN npm run build -- --output-path=./dist/out --configuration $configuration

FROM nginx:1.18
COPY --from=build-stage /app/dist/out/ /usr/share/nginx/html
COPY ./nginx-custom.conf /etc/nginx/conf.d/default.conf

2

Answers


  1. The /app directory is not inside of your docker image.
    It’s in your build stage image.
    Check the /usr/share/nginx/html directory or don’t use build stage.

    Login or Signup to reply.
  2. Sèdjro has the correct answer, but I wanted to expand on it briefly.

    You’re using what is called a multi-stage build. If you haven’t seen them already, the linked docs are a good read.

    Each FROM ... line in your Dockerfile starts a new build stage, and only the contents of the final stage are relevant to the generated Docker image.

    Other stages in the file are available as sources of the COPY --from=... directive.

    In other words, as soon as you add a second FROM ... line, as in…

    FROM node:15.7.0 as build-stage
    .
    .
    .
    FROM nginx:1.18
    

    …then the contents of the first stage are effectively discarded,
    unless you explicitly copy them into the final image using COPY --from=.... Your /app directory only exists in the first stage, since you’re copying it into a different location in the final stage.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search