So I am trying to migrate to circle 2.0 (late, I know), and I running into an issue with my docker compose setup where it was fine in 1.0.
I have 4 containers, and the server needs to be able to connect to the other containers.
Here is the docker-compose.yml:
server:
build: .
command: nodemon /app/app.js
volumes:
- .:/app
- ./container/cert.pem:/etc/ssl/certs/cert.pem
- ./container/key.pem:/etc/ssl/private/key.pem
- ./container/ca.pem:/etc/ssl/certs/ca.pem
links:
- mongo:mongo
- redis:redis
- elasticsearch:elasticsearch
restart: "on-failure:10"
mongo:
build: ./container/
redis:
image: redis:4.0.8
elasticsearch:
image: elasticsearch:2.4
ports:
- "9200:9200"
- "9300:9300"
So everything seems to be working fine, all containers come up, but server can’t connect the other containers which is weird, because here is the /etc/hosts inside the server container:
127.0.0.1 localhost
172.17.0.3 csmapi_elasticsearch_1 9f1f4689d9a5
172.17.0.4 csmapi_mongo_1 e2b565610ef9
172.17.0.2 csmapi_redis_1 dbfc8724512a
172.17.0.3 csmapi_elasticsearch_1 9f1f4689d9a5
So if csmapi_server_1 tries to connect to mongodb://csmapi_mongo_1, it fails, but through testing, if I connect instead to the IP (172.17.0.4), it works.
So why, even though the hosts file is correct, is my container not able to resolve the other containers hostnames? Why does it not seem to be using /etc/hosts?