Browse Source

Avoid adding /tcp to port exposures.

tags/v0.1.1
Chris Smith 7 years ago
parent
commit
c3b21eda0f
2 changed files with 7 additions and 5 deletions
  1. 5
    3
      docker-rerun
  2. 2
    2
      test.py

+ 5
- 3
docker-rerun View File

@@ -154,16 +154,18 @@ def handle_ports(container):
154 154
     ports = container.info['HostConfig']['PortBindings']
155 155
     if ports:
156 156
         for port, bindings in ports.items():
157
+            # /tcp is the default - no need to include it
158
+            port_name = port[:-4] if port.endswith('/tcp') else port
157 159
             for binding in bindings:
158 160
                 if binding['HostIp']:
159 161
                     container.args.append('-p=%s:%s:%s' % (binding['HostIp'],
160 162
                                                            binding['HostPort'],
161
-                                                           port))
163
+                                                           port_name))
162 164
                 elif binding['HostPort']:
163 165
                     container.args.append('-p=%s:%s' % (binding['HostPort'],
164
-                                                        port))
166
+                                                        port_name))
165 167
                 else:
166
-                    container.args.append('-p=%s' % port)
168
+                    container.args.append('-p=%s' % port_name)
167 169
 
168 170
 
169 171
 def handle_restart(container):

+ 2
- 2
test.py View File

@@ -19,8 +19,8 @@ def _run(cmd):
19 19
     ['docker', 'run', '--name=test123', '--restart=always', '-d', 'hello-world'],
20 20
     ['docker', 'run', '--name=test123', '--restart=on-failure:10', '-d', 'hello-world'],
21 21
     ['docker', 'run', '--name=test123', '--net=host', '-d', 'hello-world'],
22
-    ['docker', 'run', '--name=test123', '-d', '-p=127.0.0.1:443:443/tcp', '-p=127.0.0.1::1336/tcp', 'hello-world'],
23
-    ['docker', 'run', '--name=test123', '-d', '-p=443/tcp', 'hello-world'],
22
+    ['docker', 'run', '--name=test123', '-d', '-p=127.0.0.1:443:443', '-p=127.0.0.1::1336/udp', 'hello-world'],
23
+    ['docker', 'run', '--name=test123', '-d', '-p=443', 'hello-world'],
24 24
     ['docker', 'run', '--name=test123', '--user=root', '-d', 'hello-world', '/hello', 'foobar'],
25 25
     ['docker', 'run', '--name=test123', '--net=host', '--user=root:root', '-d', 'hello-world'],
26 26
     ['docker', 'run', '--name=test123', '--volume=/dev/null:/null', '--volume=/dev/urandom:/mnt/random', '-d', 'hello-world'],

Loading…
Cancel
Save