0

So I have three containers, for testing purpose: 1 dev-server 2 selenium-headless 3 unit.

They all run parallel and it works fine. The only problem is that my 1 dev-server container does not exit/stop when the other two hav exited and done running the tests. I also wants it exit with 1 if one of the other containers exit with code 1, of course.

What should I do and add for it to exit after the other two containers are exited?

My docker-compose file looks like this. :

version: "3"

services:
  dev-server:
    build: .
    tty: true
    hostname: yeti-ui
    container_name: yeti-ui
    ports: 
      - 127.0.0.01:8080:8080
      - 35729:35729
    environment:
      - "SKIP_DOCS=0"
      - "SCHEME=http"
      - "NODE_ENV=stage"
    entrypoint: npm
    command: run dev-server

  headless-chrome:
    build:
      context: .
      dockerfile: ./Dockerfile-headless-chrome
    cap_add:
      - SYS_ADMIN
    network_mode: "host"

  unit-test:
    build: .
    entrypoint: npm
    command: test
  • Usually you start all services with `docker-compose up` and destroy with `docker-compose down`. Is it not working like that? – Ahmad Abdelghany Aug 02 '17 at 23:14
  • The problem here is that, when I do docker-compose up. All my three containeres will run and two of them exit while the other one is still running. I want it to automatically stop the first container to/automatically do a docker-compse stop. Even though I add docker-compose down after docker-compose up in my makefile, the docker-compose down will never reach since the container never exits. –  Aug 02 '17 at 23:23
  • did you try `docker-compose up --abort-on-container-exit`? – Ahmad Abdelghany Aug 02 '17 at 23:29
  • Yes. This is not working either because my dev-server container needs to wait until the other two are exited. The above command exits my dev-server container as one of the other two are exited, which means one of them will not be done running yet –  Aug 02 '17 at 23:33

2 Answers2

0

You can use:

docker-compose up --abort-on-container-exit

Which will stop all containers if one of your containers stops. See documentation.

n00b
  • 5,843
  • 11
  • 52
  • 82
  • Yeah, but since I have 3 containers, I want 2 of them be done before the first gets exited. This does not seem to be for that reason, right? –  Aug 02 '17 at 23:21
0

I thnink your two options are:

  1. Use docker-compose runto run the services separately and check for exit codes.
  2. Use docker-compose up then parsing the output of docker-compose ps.

Check out this Related Answer

Ahmad Abdelghany
  • 11,983
  • 5
  • 41
  • 36
  • Can you please describe your answers? Im pretty new at this so I dont really know what you mean. Checking exit codes will still be the same problem as abor on container exit right? How do I parse the output of docker-compose? –  Aug 03 '17 at 16:45
  • Both approached are clarified clearly in the link. I just did not find any value in quoting it. Just have a look at the link in my answer and let me know if you need further help/clarification. – Ahmad Abdelghany Aug 04 '17 at 09:47
  • It would not be the same as `abort-on-container-exit` because you will be running each service "container" separately not in one go. – Ahmad Abdelghany Aug 04 '17 at 09:48