@@ -70,47 +70,122 @@ you build this functionality into third-party tooling.
7070## Manage labels on objects
7171
7272Each type of object with support for labels has mechanisms for adding and
73- managing them and using them as they relate to that type of object. These links
74- provide a good place to start learning about how you can use labels in your
75- Docker deployments.
73+ managing them and using them as they relate to that type of object.
7674
77- Labels on images, containers, local daemons, volumes, and networks are static for
78- the lifetime of the object. To change these labels you must recreate the object.
79- Labels on Swarm nodes and services can be updated dynamically.
75+ Labels on images, containers, local daemons, volumes, and networks are static
76+ for the lifetime of the object. To change these labels you must recreate the
77+ object. Labels on Swarm nodes and services can be updated dynamically.
8078
81- - Images and containers
79+ ### Images
8280
83- - [ Adding labels to images] ( /reference/dockerfile.md#label )
84- - [ Overriding a container's labels at runtime] ( /reference/cli/docker/container/run/#label )
85- - [ Inspecting labels on images or containers] ( /reference/cli/docker/inspect/ )
86- - [ Filtering images by label] ( /reference/cli/docker/image/ls/#filter )
87- - [ Filtering containers by label] ( /reference/cli/docker/container/ls/#filter )
81+ Add labels to images using the [ ` LABEL ` instruction] ( /reference/dockerfile.md#label ) in a Dockerfile:
8882
89- - Local Docker daemons
83+ ``` dockerfile
84+ LABEL com.example.version="1.0"
85+ LABEL com.example.description="Web application"
86+ ```
9087
91- - [ Adding labels to a Docker daemon at runtime ] ( /reference/cli/dockerd.md )
92- - [ Inspecting a Docker daemon's labels ] ( /reference/cli/docker/system/info/ )
88+ You can also set labels at build time with the ` --label ` flag, without needing
89+ a ` LABEL ` instruction in the Dockerfile:
9390
94- - Volumes
91+ ``` console
92+ $ docker build --label " com.example.version=1.0" -t myapp .
93+ ```
9594
96- - [ Adding labels to volumes] ( /reference/cli/docker/volume/create/ )
97- - [ Inspecting a volume's labels] ( /reference/cli/docker/volume/inspect/ )
98- - [ Filtering volumes by label] ( /reference/cli/docker/volume/ls/#filter )
95+ Inspect labels on an image using ` docker inspect ` :
9996
100- - Networks
97+ ``` console
98+ $ docker inspect --format=' {{json .Config.Labels}}' myapp
99+ ```
101100
102- - [ Adding labels to a network] ( /reference/cli/docker/network/create/ )
103- - [ Inspecting a network's labels] ( /reference/cli/docker/network/inspect/ )
104- - [ Filtering networks by label] ( /reference/cli/docker/network/ls/#filter )
101+ Filter images by label with [ ` docker image ls --filter ` ] ( /reference/cli/docker/image/ls/#filter ) :
105102
106- - Swarm nodes
103+ ``` console
104+ $ docker image ls --filter " label=com.example.version"
105+ ```
107106
108- - [ Adding or updating a Swarm node's labels] ( /reference/cli/docker/node/update/#label-add )
109- - [ Inspecting a Swarm node's labels] ( /reference/cli/docker/node/inspect/ )
110- - [ Filtering Swarm nodes by label] ( /reference/cli/docker/node/ls/#filter )
107+ ### Containers
111108
112- - Swarm services
113- - [ Adding labels when creating a Swarm service] ( /reference/cli/docker/service/create/#label )
114- - [ Updating a Swarm service's labels] ( /reference/cli/docker/service/update/ )
115- - [ Inspecting a Swarm service's labels] ( /reference/cli/docker/service/inspect/ )
116- - [ Filtering Swarm services by label] ( /reference/cli/docker/service/ls/#filter )
109+ Override or add labels when starting a container with
110+ [ ` docker run --label ` ] ( /reference/cli/docker/container/run/#label ) :
111+
112+ ``` console
113+ $ docker run --label " com.example.env=prod" myapp
114+ ```
115+
116+ Inspect labels on a container:
117+
118+ ``` console
119+ $ docker inspect --format=' {{json .Config.Labels}}' mycontainer
120+ ```
121+
122+ Filter containers by label with [ ` docker container ls --filter ` ] ( /reference/cli/docker/container/ls/#filter ) :
123+
124+ ``` console
125+ $ docker container ls --filter " label=com.example.env=prod"
126+ ```
127+
128+ ### Local Docker daemons
129+
130+ Add labels to the Docker daemon by passing ` --label ` flags when starting
131+ ` dockerd ` , or by setting ` "labels" ` in the
132+ [ daemon configuration file] ( /reference/cli/dockerd.md#daemon-configuration-file ) :
133+
134+ ``` json
135+ {
136+ "labels" : [" com.example.environment=production" ]
137+ }
138+ ```
139+
140+ View daemon labels with ` docker system info ` .
141+
142+ ### Volumes
143+
144+ Add labels when [ creating a volume] ( /reference/cli/docker/volume/create/ ) :
145+
146+ ``` console
147+ $ docker volume create --label " com.example.purpose=database" myvolume
148+ ```
149+
150+ Inspect volume labels:
151+
152+ ``` console
153+ $ docker volume inspect myvolume --format=' {{json .Labels}}'
154+ ```
155+
156+ Filter volumes by label with [ ` docker volume ls --filter ` ] ( /reference/cli/docker/volume/ls/#filter ) :
157+
158+ ``` console
159+ $ docker volume ls --filter " label=com.example.purpose"
160+ ```
161+
162+ ### Networks
163+
164+ Add labels when [ creating a network] ( /reference/cli/docker/network/create/ ) :
165+
166+ ``` console
167+ $ docker network create --label " com.example.purpose=frontend" mynetwork
168+ ```
169+
170+ Inspect network labels:
171+
172+ ``` console
173+ $ docker network inspect mynetwork --format=' {{json .Labels}}'
174+ ```
175+
176+ Filter networks by label with [ ` docker network ls --filter ` ] ( /reference/cli/docker/network/ls/#filter ) :
177+
178+ ``` console
179+ $ docker network ls --filter " label=com.example.purpose"
180+ ```
181+
182+ ### Swarm nodes
183+
184+ - [ Adding or updating a Swarm node's labels] ( /reference/cli/docker/node/update/#label-add )
185+ - [ Filtering Swarm nodes by label] ( /reference/cli/docker/node/ls/#filter )
186+
187+ ### Swarm services
188+
189+ - [ Adding labels when creating a Swarm service] ( /reference/cli/docker/service/create/#label )
190+ - [ Updating a Swarm service's labels] ( /reference/cli/docker/service/update/ )
191+ - [ Filtering Swarm services by label] ( /reference/cli/docker/service/ls/#filter )
0 commit comments