I have two processes that I have containerised as container1 and container2. I would like to run both of these together using Docker Compose. container1 should connect to container2. This does not currently work and I cannot figure out the problem.
Some test scenarios I have tried...
Run container2 using Docker Compose:
version: '2' services: container2: image: container2 ports: - "4003:4003" Now run container1 source code from outside Docker and point to 127.0.0.1:4003 - connects ok.
Or run container2 as above; note the IP address, then run container1 also from Compose, referencing the IP directly - also connects ok:
version: '2' services: container1: image: container1 environment: - HOST=172.18.0.2 - PORT=4003 But when I place them both in the same docker-compose.yml file, container1 never connects to container2, but can ping it by name - what gives?
version: '2' services: container1: image: container1 depends_on: - container2 environment: - HOST=container2 - PORT=4003 container2: image: container2 ports: - "4003:4003" Edit: it appears that there is a problem with using the container alias, as this also works:
version: '2' services: container1: image: container1 depends_on: - container2 environment: - HOST=172.18.0.2 - PORT=4003 container2: image: container2 ports: - "4003:4003" A further piece of the puzzle: internally container2 is using socat to expose the port the app is listening on:
echo "Forking :::4001 onto 0.0.0.0:4003\n" socat TCP-LISTEN:4003,fork TCP:127.0.0.1:4001 Seems that this doesn't work with the container alias for some reason?