Kunkka Kunkka - 1 year ago 88
Node.js Question

volume not getting mounted in nginx container

I have the below compose file which starts 2 containers

container_name: nginx
build: ./nginx/
- "80:80"
- node:node
- node

container_name: node
build: .
env_file: .env

command: npm run package

The dockerfile for node

FROM node:6.0

# Create app directory
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app

# Install app dependencies
COPY package.json /usr/src/app/
RUN npm install

# Bundle app source
COPY . /usr/src/app


docker-compose up
doesnt seem to mount the node volumes into nginx. I require the volume to serve the static files from node

location / {
#The location setting lets you configure how nginx responds to requests for resources within the server.
proxy_pass http://node:8000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

location ~* \.(js|css|png|jpeg)$ {
root /usr/src/app/public;
expires 30d;

the volume is present in node

avernus@avernus-VirtualBox:~$ docker exec -it node bash
root@127bddea4e31:/usr/src/app# ls
Dockerfile docker-compose.override.yml migrations postgres-test shared webpack.config.js
Makefile docker-compose.prod.yml node_modules public socketcluster webpack.production.config.js
client docker-compose.yml package.json server test

But Nginx doesnt seem to have the volumes

avernus@avernus-VirtualBox:~$ docker exec -it nginx bash
root@47ca17fac4b3:/# cd /usr/src/app
bash: cd: /usr/src/app: No such file or directory

Is there something else i'm missing?

Answer Source

The node part of your docker-compose.yml doesn't declare any volumes - how should docker know which part of your node image should be shared! Try adding something like this to the node service in your compose yaml:

  - /usr/src/app
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download