2020-05-19 10:21:38 +02:00
|
|
|
# docker run
|
|
|
|
|
|
|
|
> Run a command in a new Docker container.
|
2024-09-26 03:21:43 -07:00
|
|
|
> More information: <https://docs.docker.com/reference/cli/docker/container/run/>.
|
2020-05-19 10:21:38 +02:00
|
|
|
|
|
|
|
- Run command in a new container from a tagged image:
|
|
|
|
|
|
|
|
`docker run {{image:tag}} {{command}}`
|
|
|
|
|
|
|
|
- Run command in a new container in background and display its ID:
|
|
|
|
|
2025-03-17 12:09:59 +02:00
|
|
|
`docker run {{[-d|--detach]}} {{image}} {{command}}`
|
2020-05-19 10:21:38 +02:00
|
|
|
|
|
|
|
- Run command in a one-off container in interactive mode and pseudo-TTY:
|
|
|
|
|
2025-03-17 12:09:59 +02:00
|
|
|
`docker run --rm {{[-i|--interactive]}} {{[-t|--tty]}} {{image}} {{command}}`
|
2020-05-19 10:21:38 +02:00
|
|
|
|
|
|
|
- Run command in a new container with passed environment variables:
|
|
|
|
|
2025-03-17 12:09:59 +02:00
|
|
|
`docker run {{[-e|--env]}} '{{variable}}={{value}}' {{[-e|--env]}} {{variable}} {{image}} {{command}}`
|
2020-05-19 10:21:38 +02:00
|
|
|
|
|
|
|
- Run command in a new container with bind mounted volumes:
|
|
|
|
|
2025-03-17 12:09:59 +02:00
|
|
|
`docker run {{[-v|--volume]}} {{/path/to/host_path}}:{{/path/to/container_path}} {{image}} {{command}}`
|
2020-05-19 10:21:38 +02:00
|
|
|
|
|
|
|
- Run command in a new container with published ports:
|
|
|
|
|
2025-03-17 12:09:59 +02:00
|
|
|
`docker run {{[-p|--publish]}} {{host_port}}:{{container_port}} {{image}} {{command}}`
|
2021-11-06 21:18:08 +01:00
|
|
|
|
|
|
|
- Run command in a new container overwriting the entrypoint of the image:
|
|
|
|
|
|
|
|
`docker run --entrypoint {{command}} {{image}}`
|
|
|
|
|
|
|
|
- Run command in a new container connecting it to a network:
|
|
|
|
|
|
|
|
`docker run --network {{network}} {{image}}`
|