0

If an application is running inside a docker and wants to write to /etc/nginx/conf.d directory of host OS, how could I pass on this instruction in the docker-compose file? SO whenever an attempt to write to /etc/nginx/conf.d is made, it writes into the file of the host OS This is how my docker-compose.yml looks right now

myapp:
 container_name: myapp
 restart: always
 build: .
 ports:
   - "3001:3001"
Amanda
  • 2,013
  • 3
  • 24
  • 57
  • Have you tried [using volumes](https://docs.docker.com/storage/volumes/)? – Sebastian Kaczmarek Dec 03 '20 at 08:53
  • @SebastianKaczmarek I went through this document before posting here. But I could not understand, how exactly to use this for my case. Could you help answer this? – Amanda Dec 03 '20 at 08:55

1 Answers1

2

docker volumes
: Mount host paths or named volumes, specified as sub-options to a service.

https://docs.docker.com/storage/volumes/
https://docs.docker.com/compose/compose-file/

myapp:
 container_name: myapp
 restart: always
 build: .
 ports:
   - "3001:3001"
 volumes:
   - <your_host_pc_path>:/etc/nginx/conf.d

Whenever /etc/nginx/conf.d is changed in the docker container, <your_host_pc_path> is also changed. Likewise, even if a change in <your_host_pc_path> occurs, /etc/nginx/conf.d of the docker container is changed.

myeongkil kim
  • 2,465
  • 4
  • 16
  • 22
  • And how could I run a command on the host from docker? A script running inside docker has to run a command present on docker. – Amanda Dec 03 '20 at 10:40
  • [How to run shell script on host from docker container?](https://stackoverflow.com/questions/32163955/how-to-run-shell-script-on-host-from-docker-container) – myeongkil kim Dec 04 '20 at 12:17