فهرست منبع

Merge pull request #1011 from sdake/master

Add a --pid=host feature to expose the host PID space to the container
Aanand Prasad 11 سال پیش
والد
کامیت
619e783a05
4فایلهای تغییر یافته به همراه25 افزوده شده و 0 حذف شده
  1. 1 0
      compose/config.py
  2. 3 0
      compose/service.py
  3. 10 0
      docs/yml.md
  4. 11 0
      tests/integration/service_test.py

+ 1 - 0
compose/config.py

@@ -20,6 +20,7 @@ DOCKER_CONFIG_KEYS = [
     'links',
     'links',
     'mem_limit',
     'mem_limit',
     'net',
     'net',
+    'pid',
     'ports',
     'ports',
     'privileged',
     'privileged',
     'restart',
     'restart',

+ 3 - 0
compose/service.py

@@ -25,6 +25,7 @@ DOCKER_START_KEYS = [
     'dns_search',
     'dns_search',
     'env_file',
     'env_file',
     'net',
     'net',
+    'pid',
     'privileged',
     'privileged',
     'restart',
     'restart',
 ]
 ]
@@ -434,6 +435,7 @@ class Service(object):
         privileged = options.get('privileged', False)
         privileged = options.get('privileged', False)
         cap_add = options.get('cap_add', None)
         cap_add = options.get('cap_add', None)
         cap_drop = options.get('cap_drop', None)
         cap_drop = options.get('cap_drop', None)
+        pid = options.get('pid', None)
 
 
         dns = options.get('dns', None)
         dns = options.get('dns', None)
         if isinstance(dns, six.string_types):
         if isinstance(dns, six.string_types):
@@ -457,6 +459,7 @@ class Service(object):
             restart_policy=restart,
             restart_policy=restart,
             cap_add=cap_add,
             cap_add=cap_add,
             cap_drop=cap_drop,
             cap_drop=cap_drop,
+            pid_mode=pid
         )
         )
 
 
     def _get_image_name(self, image):
     def _get_image_name(self, image):

+ 10 - 0
docs/yml.md

@@ -264,6 +264,16 @@ net: "none"
 net: "container:[name or id]"
 net: "container:[name or id]"
 net: "host"
 net: "host"
 ```
 ```
+### pid
+
+```
+pid: "host"
+```
+
+Sets the PID mode to the host PID mode.  This turns on sharing between
+container and the host operating system the PID address space.  Containers
+launched with this flag will be able to access and manipulate other
+containers in the bare-metal machine's namespace and vise-versa.
 
 
 ### dns
 ### dns
 
 

+ 11 - 0
tests/integration/service_test.py

@@ -419,6 +419,17 @@ class ServiceTest(DockerClientTestCase):
         container = create_and_start_container(service)
         container = create_and_start_container(service)
         self.assertEqual(container.get('HostConfig.NetworkMode'), 'host')
         self.assertEqual(container.get('HostConfig.NetworkMode'), 'host')
 
 
+    def test_pid_mode_none_defined(self):
+        service = self.create_service('web', pid=None)
+        container = create_and_start_container(service)
+        print 'STEAK %s' % (container.get('HostConfig.PidMode'))
+        self.assertEqual(container.get('HostConfig.PidMode'), '')
+
+    def test_pid_mode_host(self):
+        service = self.create_service('web', pid='host')
+        container = create_and_start_container(service)
+        self.assertEqual(container.get('HostConfig.PidMode'), 'host')
+
     def test_dns_no_value(self):
     def test_dns_no_value(self):
         service = self.create_service('web')
         service = self.create_service('web')
         container = create_and_start_container(service)
         container = create_and_start_container(service)