Search code examples
docker-composedocker-swarmtraefik

how to work two seperate docker-compose files with traefik where swarm enabled


I have two different docker-compose file having different services(project space) which I want to run on same swarm because I want to use traefik as reverse proxy how could I do that?


Solution

  • You have to use a common image registry and prebuild images before deploying to swarm:

    first compose file:

    services:
        my_service:
            build: ./my_service
            image: my-registry-host/my_service:latest
            ...
    

    second compose file:

    services:
    
        my_other_service:
            build: ./my_other_service
            image: my-registry-host/my_other_service:latest
            ...
        my_service:
            image: my-registry-host/my_service:latest
            ...
    
        traefik:
            image: traefik:v2.0
            ...
    

    when you build the services in the first file they are uploaded to your common registry my-registry-host. An when you deploy the second file you will see that the image will be got from the common registry and stack runs as expected.