Combine container definition in multiple docker

In my docker build, there is a nginx proxy container definition:

nginx-proxy: image: jwilder/nginx-proxy ports: - "80:80" volumes: - /var/run/docker.sock:/tmp/docker.sock:ro 

I would like to define this container in several docker-compose.yml files (one for each project).

How can I do this without stopping every time in the container (because it uses port 80)? The idea is this: if there are no nginx-proxy containers, run this, otherwise use an executable file.

+5
source share
1 answer

You can have one nginx for all your projects. In this case, you need to have the only_nginx / docker-compose.yml file where you have] the nginx service and use

 projectx_service: extends: file: /path_to/only_nginx/docker-compose.yml service: nginx-proxy ... 

this block in every project that creates files for docker.

Example:

only_nginx / docker-compose.yml :

 nginx-proxy: image: jwilder/nginx-proxy ports: - "80:80" volumes: - /var/run/docker.sock:/tmp/docker.sock:ro 

project1 / Docker-compose.yml

 project1_service: extends: file: /path_to/only_nginx/docker-compose.yml service: nginx-proxy ... 

project2 / Docker-compose.yml

 project2_service: extends: file: /path_to/only_nginx/docker-compose.yml service: nginx-proxy ... 
-1
source

Source: https://habr.com/ru/post/1257710/


All Articles