5

In my docker-compose 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 multiple docker-compose.yml file (one per project).

How can I do that, without stopping each time the container (because is using the port 80)? The idea is: if there are no nginx-proxy containers running, run this, otherwise use the running one.

nwinkler
  • 52,665
  • 21
  • 154
  • 168
Oscar Fanelli
  • 3,337
  • 2
  • 28
  • 40

1 Answers1

-1

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

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

this kind of block in your every project docker-compose files.

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
    ...
  • This doesn't solve the original problem, but just avoid duplication of code. If I run `docker-compose up` on both projects, first is ok, second always tell me "... Bind for 0.0.0.0:80 failed: port is already allocated". Moreover, the `extends` keyword is deprecated in Docker Compose v3 – Oscar Fanelli Aug 09 '17 at 21:11