My goal was, that Jenkins container will "talk" with Ansible container in order to create Jenkins file for Jenkins pipeline.
I was expected that those two container will "join" to bridge network and get 2 IP addresses of the same network id, but instead additional two networks were created, and each container got IP of different Network id.
Also, expected that those two container will have access to the internet.
So, In my Windows 10 I'm running Docker Desktop,
I have 2 docker-compose.yml files,
One, for Jenkins container:
version: '3.7'
services:
jenkins:
image: jenkins/jenkins:lts
privileged: true
user: root
ports:
- 8080:8080
- 50000:50000
container_name: jenkins
Another, for Ansible container:
version: '2'
services:
ansible:
container_name: ansible
hostname: ansible
image: ansible
volumes:
- ~/product/ansible:/ansible
working_dir: /ansible
build:
context: .
dockerfile: Dockerfile
dns:
- 200.20.200.20
I ran the following command for each docker-compose.yml file, so I had two separate machines:
docker-compose up --build
I inspected my container's network details and found out that each container got a different Network ID, see below:
PS > docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' ansible
172.18.0.2
PS > docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' jenkins
172.19.0.2
check my docker networks section, revealed that 2 more networks were created, besides bridge, host and none:
PS > docker network ls
NETWORK ID NAME DRIVER SCOPE
8cefaed24885 ansible_default bridge local
44bedcd1622d bridge bridge local
61e1c7f7051e host host local
b5a7a7a424a4 jenkins_default bridge local
4e5d6c77cb5a none null local
Of course, inspecting bridge network shows that container key is empty:
{
"Name": "bridge",
"Id": "44bedcd1622d820ce4e29a5cd545f244ba2d303102f1956fe76069a63e7c220e",
"Created": "2021-08-25T13:13:57.6577149Z",
"Scope": "local",
"Driver": "bridge",
"EnableIPv6": false,
"IPAM": {
"Driver": "default",
"Options": null,
"Config": [
{
"Subnet": "172.17.0.0/16",
"Gateway": "172.17.0.1"
}
]
},
"Internal": false,
"Attachable": false,
"Ingress": false,
"ConfigFrom": {
"Network": ""
},
"ConfigOnly": false,
"Containers": {},
"Options": {
"com.docker.network.bridge.default_bridge": "true",
"com.docker.network.bridge.enable_icc": "true",
"com.docker.network.bridge.enable_ip_masquerade": "true",
"com.docker.network.bridge.host_binding_ipv4": "0.0.0.0",
"com.docker.network.bridge.name": "docker0",
"com.docker.network.driver.mtu": "1500"
},
"Labels": {},
"CreatedTime": 1629897237657
}
My question are:
a) Why two more docker networks were created when I ran docker-compose up --build
command?
b) How can I make those containers working with bridge network and get IPs of the same network id (the bridge network id 172.17.x.x) in order that they'll talk each other?