Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker compose orphan containers when overriding services

I want to have two docker-compose files, where one overrides another.
(The motivation comes from Docker Compose Docs)
The use case comes from the buildbot environment. The first docker-compose file should define a simple service. This is a service that is going to be tested. Let's take

version: '2'
services:
  service-node:
    build:
      context: ./res
      dockerfile: Dockerfile
    image: my/server
    env_file: .env

The second docker-compose file (let's name it docker-compose.test.yml) overrides the service-node to add a buildbot worker feature, and creates the second container, i.e. buildbot master node, that is going to control testing machinery. Let's take

version: '2'
services:
  service-node:
    build:
      context: ./res
      dockerfile: buildbot.worker.Dockerfile
    image: my/buildbot-worker
    container_name: bb-worker
    env_file: ./res/buildbot.worker.env
    environment:
      - BB_RES_DIR=/var/lib/buildbot
    networks:
      testlab:
        aliases:
          - bb-worker
    volumes:
      - ./vol/bldbot/worker:/home/bldbotworker
    depends_on:
      - bb-master

  bb-master:
    build:
      context: ./res
      dockerfile: buildbot.master.Dockerfile
    image: my/buildbot-master
    container_name: bb-master
    env_file: ./res/buildbot.master.env
    environment:
      - BB_RES_DIR=/var/lib/buildbot
    networks:
      - testlab
    expose:
      - "9989"
    volumes:
      - ./vol/bldbot/master:/var/lib/buildbot

networks:
  testlab:
    driver: bridge

Generally this configuration works, i.e. the command

docker-compose -f docker-compose.yml -f docker-compose.test.yml up -d 

builds both images and runs both containers, but there is one shortcoming, i.e. the command

docker-compose ps

shows only one service, bb-worker. At the same time

docker ps

shows both.
Furthermore, the command

docker-compose down

stops only one service, and outputs the message/warning Found orphan containers. Of course, the message refers to bb-master.

How can I override the basic docker-compose.yml file to be able to add additional non-orphan service?

like image 700
utom Avatar asked Jan 05 '17 21:01

utom


1 Answers

You need to run all docker-compose commands with the flags, e.g.:

docker-compose -f docker-compose.yml -f docker-compose.test.yml down

Alternatively, you can make this the default by writing the following to a .env file in the same folder:

COMPOSE_FILE=docker-compose.yml:docker-compose.test.yml

NOTE:

In windows you need tu use ";" as the separator (@louisvno)

like image 89
BMitch Avatar answered Nov 11 '22 22:11

BMitch