mantika / whaleprint

Manage DAB as service blueprints for docker swarm mode
MIT License
72 stars 3 forks source link

Ghost networks appears after export apply a stack #15

Open joskfg opened 7 years ago

joskfg commented 7 years ago

Currantly when you export and import a complete stack the network between the different containers dissapears and appear a new independent network per container.

We can reproduce it following this steps:

docker-compose.yml

version: "3"

networks:
  app-network:

services:
  memcached:
    image: memcached
    networks:
      - app-network
  nginx:
    image: nginx:1.11.6-alpine
    volumes:
      - ./provision/files/nginx:/etc/nginx:ro
    networks:
      - app-network
    depends_on:
      - memcached

Deploying the stack

docker stack deploy app-test -c docker-compose.yml

Getting the DAB

whaleprint export

DAB obtained

{  
   "Version":"0.1",
   "Services":{  
      "memcached":{  
         "Image":"memcached:latest@sha256:2f5402d8f6f8b359f186e211448b857b6b715a87b2879b9b68aee8fb0e44c164",
         "Labels":{  
            "com.docker.stack.namespace":"app-test"
         },
         "ServiceLabels":{  
            "com.docker.stack.namespace":"app-test"
         },
         "WorkingDir":"",
         "User":"",
         "Networks":[  
            "memcached"
         ],
         "Replicas":1
      },
      "nginx":{  
         "Image":"nginx:1.11.6-alpine@sha256:aee97412fee873bd3d8fc2331b80862d7bd58913f7b12740cae8515edc1a66e4",
         "Labels":{  
            "com.docker.stack.namespace":"app-test"
         },
         "ServiceLabels":{  
            "com.docker.stack.namespace":"app-test"
         },
         "WorkingDir":"",
         "User":"",
         "Networks":[  
            "nginx"
         ],
         "Replicas":1
      }
   }
}

We can see here the unknown networks nginx and memcached, actually we have no app-test network that is the defined in the docker-compose.yml.

We can check the service running in the cluster.

docker service inspect app-test_memcached
 "Networks": [
                {
                    "Target": "m5xyqqv44mx0jwfpsoruts0gh",
                    "Aliases": [
                        "memcached"
                    ]
                }
            ],

We can see that the network has a memcached alias, but if we check the output of network list that network corresponds to the app-test_app-network.

m5xyqqv44mx0        app-test_app-network                          overlay             swarm

Seems that the whaleprint export just uses the names and not the identifier to know the network, so when you tries to apply the DAB it generates one different network for container instead of use one for all the containers.

marcosnils commented 7 years ago

@joskfg thx for reporting. Using the target field instead of the alias seems the best. We will have to make another query to the swam to get the current Target network name. Does that makes sense?

joskfg commented 7 years ago

Yes, I think that it is the best solution.