A tutorial on how to wait for services within docker containers.
Instead of putting your
wait-scriptindocker-compose.yaml(as shown in docker-compose docs). You should put yourwait-scriptwithin your source(src) folder And executewait.shfrom Dockerfile.
Whenever your
docker-compose.yamlfile executes it builds fromDockerfileand your script executes. Now, execute your binary (golang binary) / main file(main.js)fromwait.sh
- All pull requests are welcomed
- Mail me at
amulyakashyap09@gmail.com
- 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
- Now, Kafka will be accessible via http://localhost:9092
- Add this command
localhost:9200to wait.sh file (vi wait.sh)
declare -a HOSTS=("localhost:27017" "localhost:9200" "localhost:5601" "localhost:15672", "localhost:9092")
- Run Command
docker-compose up