When using the docker-compose v2, it's not needed to create links between services. Docker 1.9 and 1.10 allows you to connect to other containers on the same (custom) network through their name.
You should be able to connect using either the name of the service or the name of the container as a hostname. Given that the name of the container is generated by docker-compose, this is not really convenient to use, so for that reason, docker-compose also adds an alias with the service name to each container.
Take this very simple example. I've used an Nginx container for convenience, but the same should apply to your situation;
version: '2'
services:
web_app:
image: nginx
db:
image: nginx
First start the project (assuming;
$ docker-compose --project-name=test up -d
Creating network "test_default" with the default driver
Creating test_db_1
Creating test_web_app_1
Then ping the "db" service from inside the test_web_app_1
container:
$ docker exec -it test_web_app_1 ping -c 2 db
PING db (172.18.0.2): 56 data bytes
64 bytes from 172.18.0.2: icmp_seq=0 ttl=64 time=0.108 ms
64 bytes from 172.18.0.2: icmp_seq=1 ttl=64 time=0.243 ms
--- db ping statistics ---
2 packets transmitted, 2 packets received, 0% packet loss
round-trip min/avg/max/stddev = 0.108/0.175/0.243/0.068 ms
If you inspect the test_db_1
container, you can see that docker-compose automatically added a "db" alias for the test_db_1
container;
$ docker inspect test_db_1
Gives: (just the NetworkSettings.Networks
part)
"Networks": {
"test_default": {
"IPAMConfig": null,
"Links": null,
"Aliases": [
"db",
"002b1875e61f"
],
"NetworkID": "0f9e2cddeca79e5a46c08294ed61dee273828607f99014f6410bda887626be70",
"EndpointID": "a941ab95586a8fdafc5075f9c5c44d745f974e5790ef6048b9e90115a22fb31f",
"Gateway": "172.18.0.1",
"IPAddress": "172.18.0.2",
"IPPrefixLen": 16,
"IPv6Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"MacAddress": "02:42:ac:12:00:02"
}
}