Communicate Two Docker Containers with “Docker Network”
Today, I am going to talk about connecting two docker containers with docker network feature.
First, we need to create at least two different docker containers.
I am going to work with “Oracle DB” and “Oracle WebLogic” docker containers.
Let’s check containers and their status with;
My containers’ name are “OracleDBOrnek” and “OracleWebLogicSarper”
docker ps -a
To communicate these two up & running docker containers,
We need to create a “Docket Network” with following command;
docker network create <network-name>
Let’s check If network is created
docker network ls
Docker network is created.
Now, Containers need to connect to the network that we jave just created.
We can make it happen with the following commands;
docker network connect <network-name> <container-name>
After connecting to the docker network, we will check the docker network information which includes Container’s given IPs.
We will use following command to check Docker Network Information;
docker network inspect <network-name>
Everything looks okay now,
We have created Docker Network, attached the containers and gave container IPs to them.
Now, we will test the communication.
First, we will attach to the one of the containers and ping other container.
Let’s attach Oracle WebLogic Container and ping Oracle DB container with following commands;
docker exec -it <container-name> /bin/bash
That’s all !