Skip to content

Commit 8b6577d

Browse files
authored
Merge pull request #24319 from dvdksn/build-fix-bakectx-labels
Fix: clarify bake dockerfile+context relationship, improve docs on managing labels
2 parents d72e7ed + 3ad54ed commit 8b6577d

2 files changed

Lines changed: 121 additions & 34 deletions

File tree

content/manuals/build/bake/targets.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,18 @@ $ docker buildx bake
5454
The properties you can set for a target closely resemble the CLI flags for
5555
`docker build`, with a few additional properties that are specific to Bake.
5656

57+
The `dockerfile` property specifies the path to the Dockerfile for a target.
58+
If you also set a `context`, the `dockerfile` path resolves relative to that
59+
context.
60+
61+
```hcl {title=docker-bake.hcl}
62+
target "default" {
63+
context = "app"
64+
# resolves to app/src/www/Dockerfile
65+
dockerfile = "src/www/Dockerfile"
66+
}
67+
```
68+
5769
For all the properties you can set for a target, see the [Bake reference](/build/bake/reference#target).
5870

5971
## Grouping targets
@@ -112,7 +124,7 @@ Supported patterns:
112124
> Always wrap wildcard patterns in quotes. Without quotes, your shell will expand the
113125
> wildcard to match files in the current directory, which usually causes errors.
114126
115-
Examples:
127+
Examples:
116128

117129
```console
118130
# Match all targets starting with 'foo-'
@@ -129,7 +141,7 @@ $ docker buildx bake "[fb]oo-bar"
129141

130142
# Matches: mtx-a-b-d, mtx-a-b-e, mtx-a-b-f
131143
$ docker buildx bake "mtx-a-b-*"
132-
```
144+
```
133145

134146
You can also combine multiple patterns:
135147

content/manuals/engine/manage-resources/labels.md

Lines changed: 107 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -70,47 +70,122 @@ you build this functionality into third-party tooling.
7070
## Manage labels on objects
7171

7272
Each 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

Comments
 (0)