mirror of https://github.com/docker/docs.git
parent
40f912237b
commit
fb0f9d56bc
|
@ -1,6 +1,6 @@
|
|||
---
|
||||
description: Runs a one-off command on a service.
|
||||
keywords: fig, composition, compose, docker, orchestration, cli, run
|
||||
keywords: fig, composition, compose, docker, orchestration, cli, run
|
||||
title: docker-compose run
|
||||
---
|
||||
|
||||
|
@ -26,24 +26,24 @@ Runs a one-time command against a service. For example, the following command st
|
|||
|
||||
docker-compose run web bash
|
||||
|
||||
Commands you use with `run` start in new containers with the same configuration as defined by the service' configuration. This means the container has the same volumes, links, as defined in the configuration file. There are two differences though.
|
||||
Commands you use with `run` start in new containers with the configuration defined by the service's configuration. This means that the resulting container has the same volumes, links, etc., as defined in the configuration file. However, there are two important differences.
|
||||
|
||||
First, the command passed by `run` overrides the command defined in the service configuration. For example, if the `web` service configuration is started with `bash`, then `docker-compose run web python app.py` overrides it with `python app.py`.
|
||||
|
||||
The second difference is the `docker-compose run` command does not create any of the ports specified in the service configuration. This prevents the port collisions with already open ports. If you *do want* the service's ports created and mapped to the host, specify the `--service-ports` flag:
|
||||
The second difference is that the `docker-compose run` command does not create any of the ports specified in the service configuration. This prevents port collisions with already-open ports. If you *do want* the service's ports to be created and mapped to the host, specify the `--service-ports` flag:
|
||||
|
||||
docker-compose run --service-ports web python manage.py shell
|
||||
|
||||
Alternatively manual port mapping can be specified. Same as when running Docker's `run` command - using `--publish` or `-p` options:
|
||||
Alternatively, manual port mapping can be specified with the `--publish` or `-p` options, just as when using `docker run`:
|
||||
|
||||
docker-compose run --publish 8080:80 -p 2022:22 -p 127.0.0.1:2021:21 web python manage.py shell
|
||||
|
||||
If you start a service configured with links, the `run` command first checks to see if the linked service is running and starts the service if it is stopped. Once all the linked services are running, the `run` executes the command you passed it. So, for example, you could run:
|
||||
If you start a service configured with links, the `run` command first checks to see if the linked service is running and starts the service if it is stopped. Once all the linked services are running, the `run` executes the command you passed it. For example, you could run:
|
||||
|
||||
docker-compose run db psql -h db -U docker
|
||||
|
||||
This would open up an interactive PostgreSQL shell for the linked `db` container.
|
||||
This will open an interactive PostgreSQL shell for the linked `db` container.
|
||||
|
||||
If you do not want the `run` command to start linked containers, specify the `--no-deps` flag:
|
||||
If you do not want the `run` command to start linked containers, use the `--no-deps` flag:
|
||||
|
||||
docker-compose run --no-deps web python manage.py shell
|
||||
|
|
Loading…
Reference in New Issue