Kunkka Kunkka -4 years ago 141
Node.js Question

nginx doesnt see updated static content

I'm using docker-compose to set up nginx and node

container_name: nginx
build: ./nginx/
- "80:80"
- "443:443"
- node:node
- node
- /etc/nginx/ssl:/etc/nginx/ssl

container_name: node
build: .
env_file: .env
- /usr/src/app
- ./logs:/usr/src/app/logs
- "8000"
- NODE_ENV=production

command: npm run package

I have node and nginx share the same volume so that nginx can serve the static content generated by node.

When i update the source code in node. I remove the node container and rebuild it via the below

docker rm node

docker-compose -f docker-compose.prod.yml up --build -d node

I can see that the new node container has the updated source code with the proper updated static content

docker exec -it node bash

root@e0cd1b990cd2:/usr/src/app# cat public/style.css

this shows the updated content i want to see

.project_detail .owner{color:#ccc;padding:10px}

However, when i login to the nginx container

docker exec -it nginx bash

root@a459b271e787:/# cat /usr/src/app/public/style.css

.project_detail .owner{padding:10px}

as you can see , nginx is not able to see the newly updated static files served by node - despite the node update. It however works if i restart the nginx container as well.

Am i doing something wrong? Do i have to restart both nginx and node containers to see the updated content?

Answer Source

Instead of sharing volume of one container with another, share a common directory on the host with both the containers. For example, if the directory is at /home/user/app, then it should be present in volumes section like:

  - /home/user/app:/usr/src/app

This should be done for both the containers.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download