0

I'm having a problem with the ordering of my Docker services in terms of how they are setup. Effectively I have five services: api (a Django Rest Framework application), db (a PostgreSQL database), elasticsearch (an Elasticsearch service), Kibana, and APM for logging.

Effectively, I need Elasticsearch to be spun up before the apm service can begin doing it's thing - but the ordering is such that Elasticsearch needs to finish before APM and Kibana can begin doing there thing.

Here is my docker-compose.yml file and all the relevant dependencies:

version: "3"

services:
  api:
    build:
      context: api
    command: python3 manage.py runserver 0.0.0.0:8000
    env_file: api/.env
    volumes:
      - ./api:/usr/src/app
    ports:
      - 8000:8000
      - 6900:6900
    depends_on:
      - db

  db:
    build: docker/db
    environment:
      - POSTGRES_DB=************
      - POSTGRES_USER=dbaccount
      - POSTGRES_PASSWORD=dbpassword
    ports:
      - 5432:5432

  elasticsearch:
    image: docker.elastic.co/elasticsearch/elasticsearch:6.5.1
    ports:
      - 9200:9200
      - 9300:9300
    environment:
      - discovery.type=single-node
      - cluster.routing.allocation.disk.threshold_enabled=false

  kibana:
    image: docker.elastic.co/kibana/kibana:6.5.1
    ports:
      - 5601:5601
    depends_on:
      - elasticsearch
  apm:
    image: docker.elastic.co/apm/apm-server:6.5.1
    volumes:
      - ./docker/apm/apm-server.yml:/usr/share/apm-server/apm-server.yml
    depends_on:
      - elasticsearch
    ports:
      - 8200:8200

Effectively the running order causes a generic Linux chroot exit code of "1" on the APM service, and requires a manual "docker-compose apm restart" for everything to get going...

Is there a way to wait for one service to fully "up" before "upping" another?

Micheal J. Roberts
  • 3,735
  • 4
  • 37
  • 76

2 Answers2

0

As explained in docker-compose documentation: https://docs.docker.com/compose/startup-order/

There is no way with docker or compose to know when a container is fully "ready" before starting their dependencies, that should be handled by each application.

There is a workaround though shown in the documentation by using the wait-for-it script: https://github.com/vishnubob/wait-for-it

Esteban Garcia
  • 2,171
  • 16
  • 24
0

There's a github thread on this here:

https://github.com/moby/moby/issues/30404#issuecomment-274825244

and here

https://github.com/docker/compose/issues/4305

If you want to use a health check for docker-compose, I suggest you use v2.1 as this is the only version supporting it. However, as explained in the above answers this functionality was removed to facilitate moving away from external docker-compose:

https://github.com/docker/compose/issues/4305#issuecomment-276527457

Rob Scully
  • 744
  • 5
  • 10