Multiple docker-compose.yml files with rancher-compose?

I’ve been reading about the docker-compose feature of Multiple Compose files, where you can customize deployments by piecing together different docker-compose.yml files.

Is it possible to pass multiple compose files to rancher-compose too? This way you can build a application stack using a docker-compose.yml file that works locally without a Rancher Load Balancer service, and when deploying to Rancher include an additional docker-compose file that adds the Rancher Load Balancer service without having to repeat the application stack.

I’m interested in this because when trying to run docker-compose.yml configuration locally that contains a Rancher Load Balancer, it doesn’t start:

docker-compose -f docker-compose-rancher.yml up
Pulling rancher-lb (rancher/load-balancer-service:latest)...
Pulling repository docker.io/rancher/load-balancer-service
ERROR: Error: image rancher/load-balancer-service not found

Here’s a docker-compose-rancher.yml file with a Rancher Load Balancer service,

rancher-lb:
  ports:
  - 20010:80/tcp
  - 20011:81/tcp
  tty: true
  image: rancher/load-balancer-service
  links:
  - nginx
  stdin_open: true
nginx:
  labels:
    io.rancher.container.pull_image: always
  tty: true
  image: nginx:stable-alpine
  stdin_open: true

Removing the rancher-lb service brings the nginx service up without issue. When I first researched this I found Rancher/load-balancer-service is missing, which makes sense but one of the questions that was never answered was how to make a compose file that works both locally and in a Rancher enviornment.

If rancher-compose supports extends and multiple compose files, similar to docker-compose, I believe this would solve the issue. Then you could have two files, one that works locally for development and one that uses includes the load balancer for deployment. An example,

docker-compose.yml for local development

nginx:
  labels:
    io.rancher.container.pull_image: always
  tty: true
  image: nginx:stable-alpine
  stdin_open: true

docker-compose-rancher.yml for deployment to a Rancher enviornment

rancher-lb:
  ports:
  - 20010:80/tcp
  - 20011:81/tcp
  tty: true
  image: rancher/load-balancer-service
  links:
  - nginx
  stdin_open: true

Then if you want to test locally using docker-compose

docker-compose -f docker-compose.yml -p local-nginx up

To deploy to a Rancher environment you can pass both compose files to make up the stack,

rancher-compose --file docker-compose.yml \
                --file docker-compose-rancher.yml \
                --rancher-file rancher-compose.yml \
                --env-file .env.export \
                --project-name ${PROJECT_NAME} \
                up \
                --upgrade \
                --confirm-upgrade \
                --pull \
                -d

By allowing multiple files developers can avoid repeating services in multiple compose files that essentially do the same thing, allowing for a cleaner deployment method.

Sounds like you are looking for https://github.com/rancher/rancher/issues/2626.

@andyshinn this is exactly what I needed! I just tried it out with rancher-compose v0.8.2 and it worked as designed. Last time I tried it a few weeks ago with a pre 0.8.0 version it wasn’t working and should have tried it with a newer version before posting.

Thank you.