1 year ago
#342229
RMartins
docker-compose.yml with nginx can't share volume
I'm trying to make the directory being served by nginx also available on host. I'm running on linux/ubuntu Part of Dockerfile:
FROM node:12.19.1-alpine as builder
... # some commands
RUN yarn build --outputHashing=all --output-path=/app/dist/
FROM nginx:1.14.1-alpine
VOLUME /var/cache/nginx
COPY docker/nginx.conf /etc/nginx/conf.d/default.conf
RUN rm -rf /var/dist/*
COPY --from=builder /app/dist/ /var/dist
CMD ["nginx", "-g", "daemon off;"]
My docker-compose.yaml:
version: "3.7"
services:
app:
image: name-image
deploy:
labels:
...
tty: true
networks:
- proxy
- my_net
volumes:
- /var/apps/myWeb/dist:/var/dist
When I deploy without the last two lines above (volumes) the site works and when I run the command below I see that the files are in the /var/dist directory inside the container: . docker exec -it <container-id> sh . ls /var/dist However, when I run with the indicated volume lines, as the directory /var/apps/myWeb/dist is empty on the host, in the container the directory /var/dist is empty as well. How do I make both of them have the build result?
I tried alternatives giving the volume a name, but the container did not start:
volumes:
- nginx_data:/var/dist
volumes:
nginx_data:
driver_opts:
type: none
device: /var/apps/myWeb/dist
o: bind
Does someone know what I did wrong?
Solved. I finally managed to fix it: volumes: - nginx_data:/var/dist volumes: nginx_data: driver_opts: o: bind type: nfs device: /var/apps/myWeb/dist
Thanks
docker
nginx
docker-compose
volumes
0 Answers
Your Answer