Explorar o código

Fix running one-off containers with --x-networking by disabling linking to self.

docker create fails if networking and links are used together.

Signed-off-by: Daniel Nephin <[email protected]>
Daniel Nephin %!s(int64=10) %!d(string=hai) anos
pai
achega
7878d38dee
Modificáronse 2 ficheiros con 11 adicións e 0 borrados
  1. 3 0
      compose/service.py
  2. 8 0
      tests/unit/service_test.py

+ 3 - 0
compose/service.py

@@ -539,6 +539,9 @@ class Service(object):
         return 1 if not numbers else max(numbers) + 1
 
     def _get_links(self, link_to_self):
+        if self.use_networking:
+            return []
+
         links = []
         for service, link_name in self.links:
             for container in service.containers():

+ 8 - 0
tests/unit/service_test.py

@@ -499,6 +499,14 @@ class ServiceTest(unittest.TestCase):
             ports=["127.0.0.1:1000-2000:2000-3000"])
         self.assertEqual(service.specifies_host_port(), True)
 
+    def test_get_links_with_networking(self):
+        service = Service(
+            'foo',
+            image='foo',
+            links=[(Service('one'), 'one')],
+            use_networking=True)
+        self.assertEqual(service._get_links(link_to_self=True), [])
+
 
 class NetTestCase(unittest.TestCase):