Docker documentation says that every container in the same compose file can be accessed from each other by using their service names. This seems to be working for all my containers except the lb.
version: "3"
services:
lb:
image: nginx
volumes:
- ./conf/nginx:/etc/nginx/conf.d/default.conf
ports:
- "8080:80"
environment:
- NGINX_HOST=foobar.com
- NGINX_PORT=80
stdin_open: true
tty: true
worker1:
build: ./rel_sync_worker/.
stdin_open: true
tty: true
depends_on :
- broker
- lb
worker2:
build: ./rel_sync_worker/.
stdin_open: true
tty: true
depends_on :
- broker
- lb
broker:
build: ./broker/.
ports:
- "4444:4444/udp"
stdin_open: true
tty: true
depends_on:
- lb
broker1.py
import socket
host = socket.gethostbyname("broker")
print "broker", host
host = socket.gethostbyname("worker1")
print "worker1", host
host = socket.gethostbyname("lb")
# host = "127.0.0.1"
print host
port = 5555
broker1 output:
broker_1 | broker 172.18.0.4
broker_1 | worker1 172.18.0.2
broker_1 | Traceback (most recent call last):
broker_1 | File "sendertest.py", line 11, in <module>
broker_1 | host = socket.gethostbyname("lb")
broker_1 | socket.gaierror: [Errno -2] Name or service not known