moh
moh

Reputation: 41

docker compose share file between containers

I have nginx container and server container. I want to edit the htpasswd file of the nginx by the server container , how I can access to file in another container? I use docker-compose but don't know how to access to path of another container.

I search about something like network share in windows(net use or something) but in containers. The htpasswd file will not be on the host machine so add volume is not option(I want let the server create this file)

Upvotes: 4

Views: 4268

Answers (1)

Deewai
Deewai

Reputation: 111

You can add the volume from one container in another container. Example:

php:
 image: php:fpm-alpine
 container_name: php
 volumes:
   - .:/var/www/order
 entrypoint:
   - php-fpm
 links:
   - mysql


nginx:
 image: nginx:alpine
 container_name: nginx
 volumes_from:
   - php
 volumes:
   - ./build/nginx.conf:/etc/nginx/conf.d/default.conf
 links:
   - php
 ports:
   - 8080:80

Now the php volume becomes accessible in the nginx container

Upvotes: 3

Related Questions