Kunkka Kunkka - 3 months ago 21
Node.js Question

volume not getting mounted in nginx container

I have the below compose file which starts 2 containers

services:
nginx:
container_name: nginx
build: ./nginx/
ports:
- "80:80"
links:
- node:node
volumes_from:
- 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

EXPOSE 8000


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

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:

volumes:
  - /usr/src/app