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

+ 12
- 0
docker-rerun View File

123
     container.image = container.info['Config']['Image']
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
 def handle_name(container):
138
 def handle_name(container):
127
     """Copies the name (--name) argument."""
139
     """Copies the name (--name) argument."""
128
     # Trim the leading / off the name. They're equivalent from docker's point
140
     # Trim the leading / off the name. They're equivalent from docker's point

+ 3
- 0
test.py View File

22
     ['docker', 'run', '--name=test123', '-d', '-p=127.0.0.1:443:443/tcp', '-p=127.0.0.1::1336/tcp', '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'],
23
     ['docker', 'run', '--name=test123', '-d', '-p=443/tcp', 'hello-world'],
24
     ['docker', 'run', '--name=test123', '--user=root', '-d', 'hello-world', '/hello', 'foobar'],
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
     ['docker', 'run', '--name=test123', '--volume=/dev/null:/null', '--volume=/dev/urandom:/mnt/random', '-d', 'hello-world'],
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
 def test_command_matches(*command):
30
 def test_command_matches(*command):
28
     _run(['docker', 'rm', '-f', 'test123'])
31
     _run(['docker', 'rm', '-f', 'test123'])

Loading…
Cancel
Save