I'm trying to understand the basics of docker/docker-compose so I embarked in a didactic experiment of my own. Basically I want to test the whole cycle of: develop the code locally, write the docker and docker-compose files, push to a github repo, clone the repo in a test directory, do docker-compose up --build and observe the magic.
To test all this I used an Angular app that I had already written. The docker file looks like this:
# base image
FROM node:10.13.0-jessie
# set working directory
RUN mkdir /usr/src/app
WORKDIR /usr/src/app
# add `/usr/src/app/node_modules/.bin` to $PATH
ENV PATH /usr/src/app/node_modules/.bin:$PATH
# install and cache app dependencies
COPY package.json /usr/src/app/package.json
RUN npm install
RUN npm install -g @angular/cli
# add app
COPY . /usr/src/app
# expose port
EXPOSE 4200
# start app
CMD ng serve --host 0.0.0.0
and the Docker-compose.yml is:
version: '3.7'
services:
myapp-frontend:
container_name: frontend
build: ./
working_dir: /usr/src/app
command: ng serve --host 0.0.0.0
ports:
- "4200:4200"
So, everything works as expected unless I decide to start developing on the test folder. In that case, after I do npm install to download all the node_modules if I try again docker-compose up --build the build fails with the following error
Traceback (most recent call last):
File "site-packages\docker\utils\build.py", line 96, in create_archive
OSError: [Errno 22] Invalid argument: 'path\\myapp-frontend\\node_modules \\.bin\\acorn'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "docker-compose", line 6, in <module>
File "compose\cli\main.py", line 71, in main
File "compose\cli\main.py", line 127, in perform_command
File "compose\cli\main.py", line 1052, in up
File "compose\cli\main.py", line 1048, in up
File "compose\project.py", line 471, in up
File "compose\service.py", line 336, in ensure_image_exists
File "compose\service.py", line 1067, in build
File "site-packages\docker\api\build.py", line 154, in build
File "site-packages\docker\utils\build.py", line 31, in tar
File "site-packages\docker\utils\build.py", line 100, in create_archive
OSError: Can not read file in context: path\myapp-frontend\node_modules\.bin\acorn
[27228] Failed to execute script docker-compose
As far as I understood, the whole building part of the Angular app is happening in the container (and in fact docker-compose works fine when i clone the repo) so why does it suddenly care of the node_modules in the local (OS) project?