Browse Source

Add support for changing network.

pull/2/head
Chris Smith 7 years ago
parent
commit
b6443e3c82
3 changed files with 25 additions and 4 deletions
  1. 2
    1
      README.md
  2. 13
    1
      docker_rerun.py
  3. 10
    2
      test.py

+ 2
- 1
README.md View File

51
  * Labels (-l/--label)
51
  * Labels (-l/--label)
52
  * Links (--link)
52
  * Links (--link)
53
  * Names (--name)
53
  * Names (--name)
54
- * Networks (--net)
54
+ * Networks (--network)
55
  * Port publications (-p)
55
  * Port publications (-p)
56
  * Restart policies (--restart)
56
  * Restart policies (--restart)
57
  * User switching (-u/--user)
57
  * User switching (-u/--user)
79
                             would happen.
79
                             would happen.
80
       --pull                Docker pull the image before re-running the container
80
       --pull                Docker pull the image before re-running the container
81
       --image IMAGE         Image to use in place of the original
81
       --image IMAGE         Image to use in place of the original
82
+      --network NETWORK     The new network configuration to use
82
       --port PORT, -p PORT  Additional port to expose
83
       --port PORT, -p PORT  Additional port to expose
83
       --tag TAG             Image tag (version) to use
84
       --tag TAG             Image tag (version) to use
84
 
85
 

+ 13
- 1
docker_rerun.py View File

165
     """Copies the network mode (--net) argument."""
165
     """Copies the network mode (--net) argument."""
166
     network = container.info['HostConfig']['NetworkMode']
166
     network = container.info['HostConfig']['NetworkMode']
167
     if network != 'default':
167
     if network != 'default':
168
-        container.args.append('--net=%s' % network)
168
+        container.args.append('--network=%s' % network)
169
 
169
 
170
 
170
 
171
 def handle_ports(container):
171
 def handle_ports(container):
219
         container.image = args.image
219
         container.image = args.image
220
 
220
 
221
 
221
 
222
+def modify_network(parser=None, args=None, container=None):
223
+    """Allows the network to be modified."""
224
+    if parser:
225
+        parser.add_argument('--network',
226
+                            help='The new network configuration to use')
227
+    elif args.network:
228
+        # Get rid of any existing network options, and add the new one
229
+        container.args = [a for a in container.args
230
+                          if not a.startswith('--network=')]
231
+        container.args.extend(['--network=%s' % args.network])
232
+
233
+
222
 def modify_port_add(parser=None, args=None, container=None):
234
 def modify_port_add(parser=None, args=None, container=None):
223
     """Allows a additional ports to be exposed."""
235
     """Allows a additional ports to be exposed."""
224
     if parser:
236
     if parser:

+ 10
- 2
test.py View File

39
     yield check, ['docker', 'run', '--env=FOO=bar baz', '--name=test123', '-d', 'hello-world']
39
     yield check, ['docker', 'run', '--env=FOO=bar baz', '--name=test123', '-d', 'hello-world']
40
     yield check, ['docker', 'run', '--name=test123', '--restart=always', '-d', 'hello-world']
40
     yield check, ['docker', 'run', '--name=test123', '--restart=always', '-d', 'hello-world']
41
     yield check, ['docker', 'run', '--name=test123', '--restart=on-failure:10', '-d', 'hello-world']
41
     yield check, ['docker', 'run', '--name=test123', '--restart=on-failure:10', '-d', 'hello-world']
42
-    yield check, ['docker', 'run', '--name=test123', '--net=host', '-d', 'hello-world']
42
+    yield check, ['docker', 'run', '--name=test123', '--network=host', '-d', 'hello-world']
43
     yield check, ['docker', 'run', '--name=test123', '-d', '-p=127.0.0.1:443:443', '-p=127.0.0.1::1336/udp', 'hello-world']
43
     yield check, ['docker', 'run', '--name=test123', '-d', '-p=127.0.0.1:443:443', '-p=127.0.0.1::1336/udp', 'hello-world']
44
     yield check, ['docker', 'run', '--name=test123', '-d', '-p=443', 'hello-world']
44
     yield check, ['docker', 'run', '--name=test123', '-d', '-p=443', 'hello-world']
45
     yield check, ['docker', 'run', '--name=test123', '-d', '-p=80:80', '-p=90', 'hello-world']
45
     yield check, ['docker', 'run', '--name=test123', '-d', '-p=80:80', '-p=90', 'hello-world']
46
     yield check, ['docker', 'run', '--name=test123', '--user=root', '-d', 'hello-world', '/hello', 'foobar']
46
     yield check, ['docker', 'run', '--name=test123', '--user=root', '-d', 'hello-world', '/hello', 'foobar']
47
-    yield check, ['docker', 'run', '--name=test123', '--net=host', '--user=root:root', '-d', 'hello-world']
47
+    yield check, ['docker', 'run', '--name=test123', '--network=host', '--user=root:root', '-d', 'hello-world']
48
     yield check, ['docker', 'run', '--name=test123', '--volume=/dev/null:/null', '--volume=/dev/urandom:/mnt/random', '-d', 'hello-world']
48
     yield check, ['docker', 'run', '--name=test123', '--volume=/dev/null:/null', '--volume=/dev/urandom:/mnt/random', '-d', 'hello-world']
49
     yield check, ['docker', 'run', '--label=com.example=123 456', '--name=test123', '-d', 'hello-world']
49
     yield check, ['docker', 'run', '--label=com.example=123 456', '--name=test123', '-d', 'hello-world']
50
     yield check, ['docker', 'run', '--label=com.example.1', '--label=com.example.2=345', '--name=test123', '-d', 'hello-world']
50
     yield check, ['docker', 'run', '--label=com.example.1', '--label=com.example.2=345', '--name=test123', '-d', 'hello-world']
73
            ['docker', 'run', '--name=test123', '-d', 'hello-world'],
73
            ['docker', 'run', '--name=test123', '-d', 'hello-world'],
74
            ['--tag', 'latest'],
74
            ['--tag', 'latest'],
75
            ['docker', 'run', '--name=test123', '-d', 'hello-world:latest'])
75
            ['docker', 'run', '--name=test123', '-d', 'hello-world:latest'])
76
+    yield (check,
77
+           ['docker', 'run', '--name=test123', '-d', 'hello-world'],
78
+           ['--network', 'none'],
79
+           ['docker', 'run', '--name=test123', '--network=none', '-d', 'hello-world'])
80
+    yield (check,
81
+           ['docker', 'run', '--name=test123', '--network=host', '-d', 'hello-world'],
82
+           ['--network', 'none'],
83
+           ['docker', 'run', '--name=test123', '--network=none', '-d', 'hello-world'])
76
 
84
 
77
 
85
 
78
 @with_setup(setup_each, teardown_each)
86
 @with_setup(setup_each, teardown_each)

Loading…
Cancel
Save