Skip to content

amulyakashyap09/wait_for_service_not_container

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Docker Compose Wait For Services Script

A tutorial on how to wait for services within docker containers.

Explanation

Instead of putting your wait-script in docker-compose.yaml (as shown in docker-compose docs). You should put your wait-script within your source(src) folder And execute wait.sh from Dockerfile.

Whenever your docker-compose.yaml file executes it builds from Dockerfile and your script executes. Now, execute your binary (golang binary) / main file (main.js) from wait.sh

Contributing contributions welcome Chrome Web Store license

  • All pull requests are welcomed
  • Mail me at amulyakashyap09@gmail.com

Usage

  1. Add your services in your docker-compose.yaml file (vi docker-compose.yaml)
zookeeper:
    image: wurstmeister/zookeeper
    ports:
      - "2181:2181"
  kafka:
    build: .
    ports:
      - "9092"
    environment:
      KAFKA_ADVERTISED_HOST_NAME: 192.168.99.100
      KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
  1. Now, Kafka will be accessible via http://localhost:9092
  2. Add this command localhost:9200 to wait.sh file (vi wait.sh)
declare -a HOSTS=("localhost:27017" "localhost:9200" "localhost:5601" "localhost:15672", "localhost:9092")
  1. Run Command docker-compose up