Browse Source

Add support for labels

tags/v0.1.1
Chris Smith 7 years ago
parent
commit
026c384b24
3 changed files with 18 additions and 2 deletions
  1. 3
    2
      README.md
  2. 12
    0
      docker-rerun
  3. 3
    0
      test.py

+ 3
- 2
README.md View File

@@ -7,7 +7,7 @@ containers using the same arguments you used previously.
7 7
 Want to update to a newer image, or add a missing port publication?
8 8
 docker-rerun's got you covered.
9 9
 
10
-## How to use
10
+## How to use it
11 11
 
12 12
 In the most basic usage, you pass in a container name and it will be
13 13
 stopped, deleted and recreated:
@@ -28,6 +28,7 @@ At present docker-rerun supports a small number of commonly used arguments:
28 28
 
29 29
     * Commands (trailing arguments)
30 30
     * Environment variables (-e/--env)
31
+    * Labels (-l/--label)
31 32
     * Names (--name)
32 33
     * Networks (--net)
33 34
     * Port publications (-p)
@@ -39,9 +40,9 @@ At present docker-rerun supports a small number of commonly used arguments:
39 40
 
40 41
 Many other command line arguments:
41 42
 
42
-    * Labels
43 43
     * Linking and aliases
44 44
     * Permissions and policies
45
+    * Advanced networking options
45 46
 
46 47
 Additional options to allow mutating the container config when rerunning.
47 48
 For example:

+ 12
- 0
docker-rerun View File

@@ -123,6 +123,18 @@ def handle_image(container):
123 123
     container.image = container.info['Config']['Image']
124 124
 
125 125
 
126
+def handle_labels(container):
127
+    """Copies the label (-l/--label) arguments."""
128
+    container_labels = set((container.info['Config']['Labels'] or {}).items())
129
+    image_labels = set((container.image_info['Config']['Labels'] or {}).items())
130
+    delta = container_labels - image_labels
131
+    for key, value in delta:
132
+        if value:
133
+            container.args.append('--label=%s=%s' % (key, value))
134
+        else:
135
+            container.args.append('--label=%s' % key)
136
+
137
+
126 138
 def handle_name(container):
127 139
     """Copies the name (--name) argument."""
128 140
     # Trim the leading / off the name. They're equivalent from docker's point

+ 3
- 0
test.py View File

@@ -22,7 +22,10 @@ def _run(cmd):
22 22
     ['docker', 'run', '--name=test123', '-d', '-p=127.0.0.1:443:443/tcp', '-p=127.0.0.1::1336/tcp', 'hello-world'],
23 23
     ['docker', 'run', '--name=test123', '-d', '-p=443/tcp', 'hello-world'],
24 24
     ['docker', 'run', '--name=test123', '--user=root', '-d', 'hello-world', '/hello', 'foobar'],
25
+    ['docker', 'run', '--name=test123', '--net=host', '--user=root:root', '-d', 'hello-world'],
25 26
     ['docker', 'run', '--name=test123', '--volume=/dev/null:/null', '--volume=/dev/urandom:/mnt/random', '-d', 'hello-world'],
27
+    ['docker', 'run', '--label=com.example=123 456', '--name=test123', '-d', 'hello-world'],
28
+    ['docker', 'run', '--label=com.example.1', '--label=com.example.2=345', '--name=test123', '-d', 'hello-world'],
26 29
 ])
27 30
 def test_command_matches(*command):
28 31
     _run(['docker', 'rm', '-f', 'test123'])

Loading…
Cancel
Save