patterndockerMinor
Networking between Docker containers
Viewed 0 times
dockercontainersbetweennetworking
Problem
I have a docker container 'A' on a host 10.11.12.13 listening on port 0.0.0.0:8443->8443/tcp I have another container 'B' on same host how wants to talk to 'A' on 8443 via host. Thus when I run command curl https://10.11.12.13:8443 inside B it gives me error as 'No route to host' but I can ping 10.11.12.13 successfully. I am not sure what else I am missing?
Can someone help regarding the issue?
Can someone help regarding the issue?
Solution
Docker actually provides DNS support for networking between containers. This means that if you define your database connection as:
This will resolve
This can either be done manually by starting both instances via the cli or automated with a docker compose script, which is my recommendation. In the compose script, from version 3, you would define the both services (aka the containers):
And at the end of the file, define the network both instances should be connected to:
http://redis:6379This will resolve
redis to the correct network address, given that you fulfill the following:- All containers are on the same network
- The containers have been named
This can either be done manually by starting both instances via the cli or automated with a docker compose script, which is my recommendation. In the compose script, from version 3, you would define the both services (aka the containers):
version: "3"
services:
web:
build: ./web
container_name: web
networks:
- backend
command: bash -c "./start.sh"
redis:
image: redis:3.2
container_name: redis
networks:
- backendAnd at the end of the file, define the network both instances should be connected to:
networks:
backend:Code Snippets
http://redis:6379version: "3"
services:
web:
build: ./web
container_name: web
networks:
- backend
command: bash -c "./start.sh"
redis:
image: redis:3.2
container_name: redis
networks:
- backendnetworks:
backend:Context
StackExchange DevOps Q#2947, answer score: 4
Revisions (0)
No revisions yet.