0

I have the following directory structure

|-Dockerfile
|-README.md
|-angula.json
|-package.json
|-...
|-src
   |-index.html
   |-main.ts
   |-...
   |app
     |-app.component.html
     |...

Now I want that everything is copied into a container when it is starting up. For that I put the following content into the Dockerfile:

From node:12.15.0-alpine

RUN mkdir -p /app
WORKDIR /app

COPY package.json /app/

RUN ["npm","install"]

COPY . /app

EXPOSE 4200/tcp

CMD ["npm", "start", "--", "--host", "0.0.0.0", "--poll", "500"]

When I now build and run the Dockerfile, I have the following issue, that the directory src and all its subdirectories are not copied.

When I run docker exec -it [container-name] sh and then type sh all files which are in the same directory as Dockerfile are there. However if I then go into the src folder it is empty.

I would expect that with the COPY . /app I am coping the complete folder and all its sub-directories to the container. Why is this not the case? What am I missing out?

Wand Maker
  • 18,476
  • 8
  • 53
  • 87
Leonard Michalas
  • 1,130
  • 1
  • 11
  • 26
  • 1
    Do you have .dockerignore next to your Dockerfile? Add `RUN ls -l /app/src` after your COPY command and rebuild your image. Check the output of the docker build command. Do you see the contents of your src directory? Also what is the docker run command that you use to start your container? – Mihai Feb 08 '20 at 16:36
  • How are you starting the container? Do you have a `.dockerignore` file? – David Maze Feb 08 '20 at 16:36
  • @Mihai @David Maze I dont not use an -dockerignore file. I am usting the following comands to build and run the container: `sudo docker built -t mean-app` and `sudo docker run -it --rm -p 4200:4200 -v ${pwd}/src:/app/src mean-app` – Leonard Michalas Feb 08 '20 at 16:39
  • You don't need `-v ${pwd}/src:/app/src` since you have already copied everything inside the image. – Mihai Feb 08 '20 at 16:41
  • @Mihai I know, but I do not want to restart the container everytime I do changes to my code. Or do you think that this is causing the issue? – Leonard Michalas Feb 08 '20 at 16:43
  • Then you can remove `COPY . /app` from the Dockerfile because it doesn't make sense in your scenario. Does this fix your issue? – Mihai Feb 08 '20 at 16:47
  • ...that produces an image that's not really useful without your local source tree; really all that's left is `FROM node`. If that's what you're looking at, working with a local Node and leaving Docker out of it will be a much easier development environment. – David Maze Feb 08 '20 at 17:05
  • This question was not related to angular - please do not tag unnecessarily – Wand Maker Feb 08 '20 at 18:24
  • @Mihai `COPY . /app` makes sense, since I need all the files, which are outside the `src` folder. When I am starting the container I am only mounting `src` and not the rest of app like all the packages. Please see my resolution of the issue below. – Leonard Michalas Feb 09 '20 at 00:06

2 Answers2

0

It was a very stupid mistake... When I mounted the src directory I used ${pwd} instead of $(pwd), which lead to the empty folder, eventhough I copied previously.

Leonard Michalas
  • 1,130
  • 1
  • 11
  • 26
0

I had to remove the src entry from .dockerignore

Master Azazel
  • 612
  • 1
  • 12
  • 32