molecule and docker networking

1,084 views
Skip to first unread message

syhR8

unread,
Mar 10, 2020, 12:29:27 PM3/10/20
to molecule-users
Hello,


I'm trying to setup some molecule tests using docker so the containers can all resolve each other by name. Normally I would do this in docker with the following...


docker network create mongos --attachable
docker run
-d --hostname config1 --name config1 --network mongos ubuntu sleep 9999
docker run
-d --hostname config2 --name config2 --network mongos ubuntu sleep 9999

Then I would be able to one of the containers and ping the other..

docker exec -ti config1 bash
root@config1
:/# ping config2
PING config2
(172.19.0.3) 56(84) bytes of data.
64 bytes from config2.mongos (172.19.0.3): icmp_seq=1 ttl=64 time=0.166 ms
64 bytes from config2.mongos (172.19.0.3): icmp_seq=2 ttl=64 time=0.086 ms
64 bytes from config2.mongos (172.19.0.3): icmp_seq=3 ttl=64 time=0.066 ms


This works as I would expect and is what I'm trying to replicate with molecule.

The relevant section of my molecue.yml is...

  - name: config1
    hostname
: config1
    image
: ubuntu:16.04
    command
: /sbin/init
    privileged
: True
    networks
:
     
- name: mongos
    attachable
: yes

I added the attachable flag after viewing the output of docker network inspect mongos when manually created as the first example and when created by molecule. The only difference I thought would be relevant was the attachable flag which was false in the molecule created network. This had no effect and I cannot resolve other contains when the network is manually created. I've tried a few variations on this config but can't get it right.

Here is a snip of inspect from a molecule created network...

[
   
{
       
"Name": "mongos",
       
"Id": "3608dfd37c373f982c2ce20312237e0f56d6c27cde9a0b069108a341dc403ac8",
       
"Created": "2020-03-10T15:28:28.449043121Z",
       
"Scope": "local",
       
"Driver": "bridge",
       
"EnableIPv6": false,
       
"IPAM": {
           
"Driver": "default",
             
"Options": null,
           
"Config": [
               
{
                   
"Subnet": "172.18.0.0/16",
                   
"Gateway": "172.18.0.1"
               
}
           
]
       
},
       
"Internal": false,
       
"Attachable": false,
       
"Ingress": false,
       
"ConfigFrom": {
           
"Network": ""
       
},
       
"ConfigOnly": false,

Here is the output from a manually created network...

[
   
{
       
"Name": "mongos",
       
"Id": "bf0b303029c1473c5ec801d0b12f0c30143aae66d52ebf1d3c2cfe0826e623e7",
       
"Created": "2020-03-10T15:48:27.732441227Z",
       
"Scope": "local",
       
"Driver": "bridge",
       
"EnableIPv6": false,
       
"IPAM": {
           
"Driver": "default",
           
"Options": {},
           
"Config": [
               
{
                   
"Subnet": "172.19.0.0/16",
                   
"Gateway": "172.19.0.1"
               
}
           
]
       
},
       
"Internal": false,
       
"Attachable": true,
       
"Ingress": false,
       
"ConfigFrom": {
           
"Network": ""
       
},
       
"ConfigOnly": false,


Does anyone know how to configure molecule.yml to get the containers talking to each other?

Cheers,

Rhys

syhR8

unread,
Mar 10, 2020, 12:31:52 PM3/10/20
to molecule-users
Some version info:

ansible 2.9.4
molecule, version 2.22

syhR8

unread,
Mar 18, 2020, 4:17:38 PM3/18/20
to molecule-users
Answered my own question...

    networks:
     
- name: "mymongo"
    network_mode
: "mymongo"

The documentation showed network_mode as "host" so naturally I assumed this set the docker network type (host, bridge, ingress etc). This appears not to be the case. Set it to the same value as the network you create and viola... it works!
Reply all
Reply to author
Forward
0 new messages