Debian Codegraph @

docs/reference/docker_compose_run.yaml

raw
1 command: docker compose run
2 short: Run a one-off command on a service
3 long: |-
4 Runs a one-time command against a service.
5
6 The following command starts the `web` service and runs `bash` as its command:
7
8 ```console
9 $ docker compose run web bash
10 ```
11
12 Commands you use with run start in new containers with configuration defined by that of the service,
13 including volumes, links, and other details. However, there are two important differences:
14
15 First, the command passed by `run` overrides the command defined in the service configuration. For example, if the
16 `web` service configuration is started with `bash`, then `docker compose run web python app.py` overrides it with
17 `python app.py`.
18
19 The second difference is that the `docker compose run` command does not create any of the ports specified in the
20 service configuration. This prevents port collisions with already-open ports. If you do want the service’s ports
21 to be created and mapped to the host, specify the `--service-ports`
22
23 ```console
24 $ docker compose run --service-ports web python manage.py shell
25 ```
26
27 Alternatively, manual port mapping can be specified with the `--publish` or `-p` options, just as when using docker run:
28
29 ```console
30 $ docker compose run --publish 8080:80 -p 2022:22 -p 127.0.0.1:2021:21 web python manage.py shell
31 ```
32
33 If you start a service configured with links, the run command first checks to see if the linked service is running
34 and starts the service if it is stopped. Once all the linked services are running, the run executes the command you
35 passed it. For example, you could run:
36
37 ```console
38 $ docker compose run db psql -h db -U docker
39 ```
40
41 This opens an interactive PostgreSQL shell for the linked `db` container.
42
43 If you do not want the run command to start linked containers, use the `--no-deps` flag:
44
45 ```console
46 $ docker compose run --no-deps web python manage.py shell
47 ```
48
49 If you want to remove the container after running while overriding the container’s restart policy, use the `--rm` flag:
50
51 ```console
52 $ docker compose run --rm web python manage.py db upgrade
53 ```
54
55 This runs a database upgrade script, and removes the container when finished running, even if a restart policy is
56 specified in the service configuration.
57 usage: docker compose run [OPTIONS] SERVICE [COMMAND] [ARGS...]
58 pname: docker compose
59 plink: docker_compose.yaml
60 options:
61 - option: build
62 value_type: bool
63 default_value: "false"
64 description: Build image before starting container
65 deprecated: false
66 hidden: false
67 experimental: false
68 experimentalcli: false
69 kubernetes: false
70 swarm: false
71 - option: cap-add
72 value_type: list
73 description: Add Linux capabilities
74 deprecated: false
75 hidden: false
76 experimental: false
77 experimentalcli: false
78 kubernetes: false
79 swarm: false
80 - option: cap-drop
81 value_type: list
82 description: Drop Linux capabilities
83 deprecated: false
84 hidden: false
85 experimental: false
86 experimentalcli: false
87 kubernetes: false
88 swarm: false
89 - option: detach
90 shorthand: d
91 value_type: bool
92 default_value: "false"
93 description: Run container in background and print container ID
94 deprecated: false
95 hidden: false
96 experimental: false
97 experimentalcli: false
98 kubernetes: false
99 swarm: false
100 - option: entrypoint
101 value_type: string
102 description: Override the entrypoint of the image
103 deprecated: false
104 hidden: false
105 experimental: false
106 experimentalcli: false
107 kubernetes: false
108 swarm: false
109 - option: env
110 shorthand: e
111 value_type: stringArray
112 default_value: '[]'
113 description: Set environment variables
114 deprecated: false
115 hidden: false
116 experimental: false
117 experimentalcli: false
118 kubernetes: false
119 swarm: false
120 - option: env-from-file
121 value_type: stringArray
122 default_value: '[]'
123 description: Set environment variables from file
124 deprecated: false
125 hidden: false
126 experimental: false
127 experimentalcli: false
128 kubernetes: false
129 swarm: false
130 - option: interactive
131 shorthand: i
132 value_type: bool
133 default_value: "true"
134 description: Keep STDIN open even if not attached
135 deprecated: false
136 hidden: false
137 experimental: false
138 experimentalcli: false
139 kubernetes: false
140 swarm: false
141 - option: label
142 shorthand: l
143 value_type: stringArray
144 default_value: '[]'
145 description: Add or override a label
146 deprecated: false
147 hidden: false
148 experimental: false
149 experimentalcli: false
150 kubernetes: false
151 swarm: false
152 - option: name
153 value_type: string
154 description: Assign a name to the container
155 deprecated: false
156 hidden: false
157 experimental: false
158 experimentalcli: false
159 kubernetes: false
160 swarm: false
161 - option: no-TTY
162 shorthand: T
163 value_type: bool
164 default_value: "true"
165 description: 'Disable pseudo-TTY allocation (default: auto-detected)'
166 deprecated: false
167 hidden: false
168 experimental: false
169 experimentalcli: false
170 kubernetes: false
171 swarm: false
172 - option: no-deps
173 value_type: bool
174 default_value: "false"
175 description: Don't start linked services
176 deprecated: false
177 hidden: false
178 experimental: false
179 experimentalcli: false
180 kubernetes: false
181 swarm: false
182 - option: publish
183 shorthand: p
184 value_type: stringArray
185 default_value: '[]'
186 description: Publish a container's port(s) to the host
187 deprecated: false
188 hidden: false
189 experimental: false
190 experimentalcli: false
191 kubernetes: false
192 swarm: false
193 - option: pull
194 value_type: string
195 default_value: policy
196 description: Pull image before running ("always"|"missing"|"never")
197 deprecated: false
198 hidden: false
199 experimental: false
200 experimentalcli: false
201 kubernetes: false
202 swarm: false
203 - option: quiet
204 shorthand: q
205 value_type: bool
206 default_value: "false"
207 description: Don't print anything to STDOUT
208 deprecated: false
209 hidden: false
210 experimental: false
211 experimentalcli: false
212 kubernetes: false
213 swarm: false
214 - option: quiet-build
215 value_type: bool
216 default_value: "false"
217 description: Suppress progress output from the build process
218 deprecated: false
219 hidden: false
220 experimental: false
221 experimentalcli: false
222 kubernetes: false
223 swarm: false
224 - option: quiet-pull
225 value_type: bool
226 default_value: "false"
227 description: Pull without printing progress information
228 deprecated: false
229 hidden: false
230 experimental: false
231 experimentalcli: false
232 kubernetes: false
233 swarm: false
234 - option: remove-orphans
235 value_type: bool
236 default_value: "false"
237 description: Remove containers for services not defined in the Compose file
238 deprecated: false
239 hidden: false
240 experimental: false
241 experimentalcli: false
242 kubernetes: false
243 swarm: false
244 - option: rm
245 value_type: bool
246 default_value: "false"
247 description: Automatically remove the container when it exits
248 deprecated: false
249 hidden: false
250 experimental: false
251 experimentalcli: false
252 kubernetes: false
253 swarm: false
254 - option: service-ports
255 shorthand: P
256 value_type: bool
257 default_value: "false"
258 description: |
259 Run command with all service's ports enabled and mapped to the host
260 deprecated: false
261 hidden: false
262 experimental: false
263 experimentalcli: false
264 kubernetes: false
265 swarm: false
266 - option: tty
267 shorthand: t
268 value_type: bool
269 default_value: "true"
270 description: Allocate a pseudo-TTY
271 deprecated: false
272 hidden: true
273 experimental: false
274 experimentalcli: false
275 kubernetes: false
276 swarm: false
277 - option: use-aliases
278 value_type: bool
279 default_value: "false"
280 description: |
281 Use the service's network useAliases in the network(s) the container connects to
282 deprecated: false
283 hidden: false
284 experimental: false
285 experimentalcli: false
286 kubernetes: false
287 swarm: false
288 - option: user
289 shorthand: u
290 value_type: string
291 description: Run as specified username or uid
292 deprecated: false
293 hidden: false
294 experimental: false
295 experimentalcli: false
296 kubernetes: false
297 swarm: false
298 - option: volume
299 shorthand: v
300 value_type: stringArray
301 default_value: '[]'
302 description: Bind mount a volume
303 deprecated: false
304 hidden: false
305 experimental: false
306 experimentalcli: false
307 kubernetes: false
308 swarm: false
309 - option: workdir
310 shorthand: w
311 value_type: string
312 description: Working directory inside the container
313 deprecated: false
314 hidden: false
315 experimental: false
316 experimentalcli: false
317 kubernetes: false
318 swarm: false
319 inherited_options:
320 - option: dry-run
321 value_type: bool
322 default_value: "false"
323 description: Execute command in dry run mode
324 deprecated: false
325 hidden: false
326 experimental: false
327 experimentalcli: false
328 kubernetes: false
329 swarm: false
330 deprecated: false
331 hidden: false
332 experimental: false
333 experimentalcli: false
334 kubernetes: false
335 swarm: false
336