Docker Community Forums

Share and learn in the Docker community.

Container will not start because other container has not started


(Gthoman) #1

Hello,

Pretty new to docker and was asked to use docker-compose to get two containers working together. I have a service that connects to NATS and it fails if it can’t connect. I’m getting:
panic: nats: no servers available for connection

Here is my compose file:
version: “2”

services:
myservice:
build: .
ports:
- "3421"
depends_on:
- nats
nats:
image: apcera/gnatsd
ports:
- “4222:4222”
- "8333:8333"
I have seen other people talk about this happening sometimes when using databases. They talked about using a script, I guess to test whether the db was up then connect? But didn’t go into detail on how/where to do this(Dockerfile, docker-compose?) Any help or ideas would be greatly appreciated. My environment is:
OS: Unbuntu 14.04
Docker version:
Client:
Version: 1.12.1
API version: 1.24
Go version: go1.6.3
Git commit: 23cf638
Built: Thu Aug 18 05:22:43 2016
OS/Arch: linux/amd64

Server:
Version: 1.12.1
API version: 1.24
Go version: go1.6.3
Git commit: 23cf638
Built: Thu Aug 18 05:22:43 2016
OS/Arch: linux/amd64

docker-compose version
docker-compose version 1.8.1, build 878cff1
docker-py version: 1.10.3
CPython version: 2.7.6
OpenSSL version: OpenSSL 1.0.1f 6 Jan 2014


(Gthoman) #2

Figured it out, created a script to check whether NATS was running, and once it was it would start my service. I used the ENTRYPOINT inside the service Dockerfile to point to the script.