You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Compose freshness: startup order, profiles, lifecycle hooks, project name (docker#22949)
<!--Delete sections as needed -->
## Description
Freshness to a few how-tos pages. also fixes and closesdocker#21417
## Related issues or tickets
<!-- Related issues, pull requests, or Jira tickets -->
## Reviews
<!-- Notes for reviewers here -->
<!-- List applicable reviews (optionally @tag reviewers) -->
- [ ] Technical review
- [ ] Editorial review
- [ ] Product review
Copy file name to clipboardExpand all lines: content/manuals/compose/how-tos/profiles.md
+14-60Lines changed: 14 additions & 60 deletions
Original file line number
Diff line number
Diff line change
@@ -85,6 +85,12 @@ If you want to enable all profiles at the same time, you can run `docker compose
85
85
86
86
## Auto-starting profiles and dependency resolution
87
87
88
+
When you explicitly target a service on the command line that has one or more profiles assigned, you do not need to enable the profile manually as Compose runs that service regardless of whether its profile is activated. This is useful for running one-off services or debugging tools.
89
+
90
+
Only the targeted service (and any of its declared dependencies via `depends_on`) is started. Other services that share the same profile will not be started unless:
91
+
- They are also explicitly targeted, or
92
+
- The profile is explicitly enabled using `--profile` or `COMPOSE_PROFILES`.
93
+
88
94
When a service with assigned `profiles` is explicitly targeted on the command
89
95
line its profiles are started automatically so you don't need to start them
90
96
manually. This can be used for one-off services and debugging tools.
@@ -108,72 +114,19 @@ services:
108
114
```
109
115
110
116
```sh
111
-
# Only start backend and db
117
+
# Only start backend and db (no profiles involved)
112
118
$ docker compose up -d
113
119
114
-
# This runs db-migrations (and, if necessary, start db)
115
-
# by implicitly enabling the profiles "tools"
120
+
# Run the db-migrations service without manually enabling the 'tools' profile
116
121
$ docker compose run db-migrations
117
122
```
118
123
119
-
But keep in mind that `docker compose` only automatically starts the
120
-
profiles of the services on the command line and not of any dependencies.
121
-
122
-
This means that any other services the targeted service `depends_on` should either:
123
-
- Share a common profile
124
-
- Always be started, by omitting `profiles` or having a matching profile started explicitly
125
-
126
-
```yaml
127
-
services:
128
-
web:
129
-
image: web
130
-
131
-
mock-backend:
132
-
image: backend
133
-
profiles: ["dev"]
134
-
depends_on:
135
-
- db
136
-
137
-
db:
138
-
image: mysql
139
-
profiles: ["dev"]
140
-
141
-
phpmyadmin:
142
-
image: phpmyadmin
143
-
profiles: ["debug"]
144
-
depends_on:
145
-
- db
146
-
```
147
-
148
-
```sh
149
-
# Only start "web"
150
-
$ docker compose up -d
151
-
152
-
# Start mock-backend (and, if necessary, db)
153
-
# by implicitly enabling profiles "dev"
154
-
$ docker compose up -d mock-backend
155
-
156
-
# This fails because profiles "dev" is not enabled
157
-
$ docker compose up phpmyadmin
158
-
```
159
-
160
-
Although targeting `phpmyadmin` automatically starts the profiles `debug`, it doesn't automatically start the profiles required by `db` which is `dev`.
124
+
In this example, `db-migrations` runs even though it is assigned to the tools profile, because it was explicitly targeted. The `db` service is also started automatically because it is listed in `depends_on`.
161
125
162
-
To fix this you either have to add the `debug` profile to the `db` service:
163
-
164
-
```yaml
165
-
db:
166
-
image: mysql
167
-
profiles: ["debug", "dev"]
168
-
```
169
-
170
-
or start the `dev` profile explicitly:
171
-
172
-
```console
173
-
# Profiles "debug" is started automatically by targeting phpmyadmin
174
-
$ docker compose --profile dev up phpmyadmin
175
-
$ COMPOSE_PROFILES=dev docker compose up phpmyadmin
176
-
```
126
+
If the targeted service has dependencies that are also gated behind a profile, you must ensure those dependencies are either:
127
+
- In the same profile
128
+
- Started separately
129
+
- Not assigned to any profile so are always enabled
177
130
178
131
## Stop application and services with specific profiles
179
132
@@ -208,6 +161,7 @@ services:
208
161
```
209
162
210
163
if you only want to stop the `phpmyadmin` service, you can run
Copy file name to clipboardExpand all lines: content/manuals/compose/how-tos/project-name.md
+3-3Lines changed: 3 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -1,20 +1,20 @@
1
1
---
2
2
title: Specify a project name
3
3
weight: 10
4
-
description: Understand the different ways you can set a project name in Compose and what the precedence is.
4
+
description: Learn how to set a custom project name in Compose and understand the precedence of each method.
5
5
keywords: name, compose, project, -p flag, name top-level element
6
6
aliases:
7
7
- /compose/project-name/
8
8
---
9
9
10
-
In Compose, the default project name is derived from the base name of the project directory. However, you have the flexibility to set a custom project name.
10
+
By default, Compose assigns the project name based on the name of the directory that contains the Compose file. You can override this with several methods.
11
11
12
12
This page offers examples of scenarios where custom project names can be helpful, outlines the various methods to set a project name, and provides the order of precedence for each approach.
13
13
14
14
> [!NOTE]
15
15
>
16
16
> The default project directory is the base directory of the Compose file. A custom value can also be set
17
-
> for it using the [`--project-directory` command line option](/reference/cli/docker/compose.md#use--p-to-specify-a-project-name).
17
+
> for it using the [`--project-directory` command line option](/reference/cli/docker/compose.md#options).
Copy file name to clipboardExpand all lines: content/manuals/compose/how-tos/startup-order.md
+3-3Lines changed: 3 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
---
2
-
description: How to control service startup and shutdown order in Docker Compose
3
-
keywords: documentation, docs, docker, compose, startup, shutdown, order
2
+
description: Learn how to manage service startup and shutdown order in Docker Compose using depends_on and healthchecks.
3
+
keywords: docker compose startup order, compose shutdown order, depends_on, service healthcheck, control service dependencies
4
4
title: Control startup and shutdown order in Compose
5
5
linkTitle: Control startup order
6
6
weight: 30
@@ -13,7 +13,7 @@ You can control the order of service startup and shutdown with the
13
13
containers in dependency order, where dependencies are determined by
14
14
`depends_on`, `links`, `volumes_from`, and `network_mode: "service:..."`.
15
15
16
-
A good example of when you might use this is an application which needs to access a database. If both services are started with `docker compose up`, there is a chance this will fail since the application service might start before the database service and won't find a database able to handle its SQL statements.
16
+
For example, if your application needs to access a database and both services are started with `docker compose up`, there is a chance this will fail since the application service might start before the database service and won't find a database able to handle its SQL statements.
0 commit comments