Reputation: 41
I am using docker-compose to start two containers (named fd & fl4j). Second container connects to the first on startup.
If I just use "host" networking, and plain "docker run" everything works fine.
With docker-compose and a defined bridge network (loggernw) the second container fails to connect to the first. May not be relevant but stating - the second container is a java spring-boot app.
Additional info: Even without docker-compose but using a "docker run" and a defined bridge network, the connection attempt fails. Also, within the second app, I am using the string "127.0.0.1" to attempt connection.
docker-compose below -
version: '3.8'
services:
fd:
image: fluentwithes
container_name: fd
ports:
- 24224:24224
expose:
- "24224"
volumes:
- /home/hrishikesh/work/bitbucket/logger/integration/docker/runs/fluentd:/fluentd/etc
networks:
- loggernw
fl4j:
image: fluentl4java
container_name: fl4j
ports:
- 9090:9090
expose:
- "9090"
networks:
- loggernw
networks:
loggernw:
driver: bridge
Upvotes: 0
Views: 621
Reputation: 361
Probably the second container tries to connect before the first is running properly. Try to use depends_on in the second container as given below. However, i think this only prevents the second container from starting before the frist started. You still might have the issue because the first did not finish startup in time. Then your service in the second has to do some retries. So maybe restart: always could be enough.
version: '3.8'
services:
fd:
image: fluentwithes
container_name: fd
ports:
- 24224:24224
expose:
- "24224"
volumes:
- /home/hrishikesh/work/bitbucket/logger/integration/docker/runs/fluentd:/fluentd/etc
networks:
- loggernw
fl4j:
depends_on:
- fd
restart: always
image: fluentl4java
container_name: fl4j
ports:
- 9090:9090
expose:
- "9090"
networks:
- loggernw
networks:
loggernw:
driver: bridge
Edit:
127.0.0.1 is wrong i think. You want put the service name there instead. The Ip might change. Try to put in second container "fd:24224" as connection string. Further information found here. https://docs.docker.com/network/bridge/
Upvotes: 2