Reputation: 4356
This is my Dockerfile:
FROM node:4
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
COPY code/* /usr/src/app/
EXPOSE 3000
VOLUME /usr/src/app/
And my Docker Compose file:
version: '2.0'
services:
my_service:
build: .
volumes:
- ./app:/usr/src/app
ports:
- 8102:3000
working_dir: /usr/src/app/
command: node src/app.js
restart: always
When I make the build:
docker-compose build
Building api_core
Step 1 : FROM node:4
---> 93b396996a16
Step 2 : RUN mkdir -p /usr/src/app
---> Using cache
---> e1ee4fd2245d
Step 3 : WORKDIR /usr/src/app
---> Using cache
---> 8824a653a9e4
Step 4 : COPY code/* /usr/src/app/
---> Using cache
---> 5e4ee9901369
Step 5 : EXPOSE 3000
---> Using cache
---> 0e10126e1651
Step 6 : VOLUME /usr/src/app/
---> Using cache
---> c1f9d36d91bc
Successfully built c1f9d36d91bc
And when I run I got this error:
docker-compose up
Error: Cannot find module '/usr/src/app/src/app.js
So Docker is telling me that it haven't found the app.js, so it is like the COPY was not working !
Upvotes: 0
Views: 1442
Reputation: 624
You are explicitly specifying a volume mapping in your compose file:
volumes:
- ./app:/usr/src/app
This will override what you have previously specify in the Dockerfile
:
COPY code/* /usr/src/app/
Both statement may provide different results depending on where you have built the image and where you will start the container. You should check that what is mapped with your compose file gives the same result.
Upvotes: 1
Reputation: 4222
You're right, you copy your app inside your docker image.
But in your docker compose section, you mount - ./app:/usr/src/app
so everything that is in your "./app" folder (on your host) is mounted in the docker container at /usr/src/app so what you copied in your dockerfile is overriden by the mount point.
Upvotes: 2