2015-06-07 22:59:58 +02:00
<!-- [metadata]>
+++
title = "Compose CLI reference"
description = "Compose CLI reference"
keywords = ["fig, composition, compose, docker, orchestration, cli, reference"]
[menu.main]
identifier = "smn_install_compose"
parent = "smn_compose_ref"
+++
<![end-metadata]-->
2014-01-27 16:03:21 +01:00
2014-10-21 15:51:01 +02:00
2015-06-07 22:59:58 +02:00
# Compose CLI reference
2014-10-21 15:51:01 +02:00
2015-02-25 09:43:33 +01:00
Most Docker Compose commands are run against one or more services. If
the service is not specified, the command will apply to all services.
2014-10-21 15:51:01 +02:00
2015-02-12 03:22:36 +01:00
For full usage information, run `docker-compose [COMMAND] --help` .
2014-10-21 15:51:01 +02:00
2014-10-03 17:19:00 +02:00
## Commands
### build
2014-01-27 16:03:21 +01:00
2015-02-12 03:22:36 +01:00
Builds or rebuilds services.
2014-01-27 16:03:21 +01:00
2015-02-12 03:22:36 +01:00
Services are built once and then tagged as `project_service` , e.g.,
`composetest_db` . If you change a service's Dockerfile or the contents of its
build directory, run `docker-compose build` to rebuild it.
2014-01-27 16:03:21 +01:00
2014-10-03 17:19:00 +02:00
### help
2014-01-27 16:03:21 +01:00
2015-02-12 03:22:36 +01:00
Displays help and usage instructions for a command.
2014-01-27 16:03:21 +01:00
2014-10-03 17:19:00 +02:00
### kill
2014-01-27 16:03:21 +01:00
2015-02-12 03:22:36 +01:00
Forces running containers to stop by sending a `SIGKILL` signal. Optionally the
signal can be passed, for example:
2014-11-03 23:46:01 +01:00
2015-01-20 18:29:28 +01:00
$ docker-compose kill -s SIGINT
2014-01-27 16:03:21 +01:00
2014-10-03 17:19:00 +02:00
### logs
2014-01-27 16:03:21 +01:00
2015-02-12 03:22:36 +01:00
Displays log output from services.
2014-01-27 16:03:21 +01:00
2014-10-03 17:19:00 +02:00
### port
2014-08-08 18:41:52 +02:00
2015-02-12 03:22:36 +01:00
Prints the public port for a port binding
2014-08-08 18:41:52 +02:00
2014-10-03 17:19:00 +02:00
### ps
2014-01-27 16:03:21 +01:00
2015-02-12 03:22:36 +01:00
Lists containers.
2014-01-27 16:03:21 +01:00
2014-10-03 17:19:00 +02:00
### pull
2014-09-10 22:06:21 +02:00
Pulls service images.
2015-04-24 22:45:18 +02:00
### restart
Restarts services.
2014-10-03 17:19:00 +02:00
### rm
2014-01-27 16:03:21 +01:00
2015-02-12 03:22:36 +01:00
Removes stopped service containers.
2014-01-27 16:03:21 +01:00
2014-10-03 17:19:00 +02:00
### run
2014-01-27 16:03:21 +01:00
2015-02-12 03:22:36 +01:00
Runs a one-off command on a service.
2014-01-27 16:03:21 +01:00
2015-02-12 03:22:36 +01:00
For example,
2014-01-27 16:03:21 +01:00
2015-01-20 18:29:28 +01:00
$ docker-compose run web python manage.py shell
2014-01-27 16:03:21 +01:00
2015-02-12 03:22:36 +01:00
will start the `web` service and then run `manage.py shell` in python.
Note that by default, linked services will also be started, unless they are
already running.
2014-01-27 16:03:21 +01:00
2015-01-19 06:46:23 +01:00
One-off commands are started in new containers with the same configuration as a
normal container for that service, so volumes, links, etc will all be created as
2015-02-12 03:22:36 +01:00
expected. When using `run` , there are two differences from bringing up a
container normally:
1. the command will be overridden with the one specified. So, if you run
`docker-compose run web bash` , the container's web command (which could default
to, e.g., `python app.py` ) will be overridden to `bash`
2014-01-30 11:50:42 +01:00
2015-02-12 03:22:36 +01:00
2. by default no ports will be created in case they collide with already opened
ports.
Links are also created between one-off commands and the other containers which
are part of that service. So, for example, you could run:
2014-01-19 21:43:31 +01:00
2015-01-20 18:29:28 +01:00
$ docker-compose run db psql -h db -U docker
2014-01-19 21:43:31 +01:00
2015-02-12 03:22:36 +01:00
This would open up an interactive PostgreSQL shell for the linked `db` container
(which would get created or started as needed).
If you do not want linked containers to start when running the one-off command,
2015-01-19 06:46:23 +01:00
specify the `--no-deps` flag:
2014-06-09 01:05:54 +02:00
2015-01-20 18:29:28 +01:00
$ docker-compose run --no-deps web python manage.py shell
2014-06-09 01:05:54 +02:00
2015-02-12 03:22:36 +01:00
Similarly, if you do want the service's ports to be created and mapped to the
host, specify the `--service-ports` flag:
2015-05-28 21:44:16 +02:00
$ docker-compose run --service-ports web python manage.py shell
2014-09-16 00:18:03 +02:00
2014-10-03 17:19:00 +02:00
### scale
2014-01-27 16:03:21 +01:00
2015-02-12 03:22:36 +01:00
Sets the number of containers to run for a service.
2014-01-27 16:03:21 +01:00
2015-02-12 03:22:36 +01:00
Numbers are specified as arguments in the form `service=num` . For example:
2014-01-27 16:03:21 +01:00
2015-01-20 18:29:28 +01:00
$ docker-compose scale web=2 worker=3
2014-01-27 16:03:21 +01:00
2014-10-03 17:19:00 +02:00
### start
2014-01-27 16:03:21 +01:00
2015-02-12 03:22:36 +01:00
Starts existing containers for a service.
2014-01-27 16:03:21 +01:00
2014-10-03 17:19:00 +02:00
### stop
2014-01-27 16:03:21 +01:00
2015-02-12 03:22:36 +01:00
Stops running containers without removing them. They can be started again with
2015-01-19 06:46:23 +01:00
`docker-compose start` .
2014-01-27 16:03:21 +01:00
2014-10-03 17:19:00 +02:00
### up
2014-01-27 16:03:21 +01:00
2015-02-12 03:22:36 +01:00
Builds, (re)creates, starts, and attaches to containers for a service.
2014-01-27 16:03:21 +01:00
2014-06-09 01:05:54 +02:00
Linked services will be started, unless they are already running.
2015-02-12 03:22:36 +01:00
By default, `docker-compose up` will aggregate the output of each container and,
when it exits, all containers will be stopped. Running `docker-compose up -d` ,
will start the containers in the background and leave them running.
2014-01-27 16:03:21 +01:00
2015-02-12 03:22:36 +01:00
By default, if there are existing containers for a service, `docker-compose up` will stop and recreate them (preserving mounted volumes with [volumes-from]), so that changes in `docker-compose.yml` are picked up. If you do not want containers stopped and recreated, use `docker-compose up --no-recreate` . This will still start any stopped containers, if needed.
2014-01-27 16:03:21 +01:00
[volumes-from]: http://docs.docker.io/en/latest/use/working_with_volumes/
2014-10-03 17:19:00 +02:00
2015-02-12 03:22:36 +01:00
## Options
### --verbose
Shows more output
2015-04-24 22:45:18 +02:00
### -v, --version
2015-02-12 03:22:36 +01:00
Prints version and exits
### -f, --file FILE
2015-03-31 22:21:04 +02:00
Specify what file to read configuration from. If not provided, Compose will look
for `docker-compose.yml` in the current working directory, and then each parent
directory successively, until found.
2015-05-27 04:09:26 +02:00
Use a `-` as the filename to read configuration from stdin. When stdin is used
all paths in the configuration will be relative to the current working
directory.
2015-02-12 03:22:36 +01:00
### -p, --project-name NAME
Specifies an alternate project name (default: current directory name)
2014-10-03 17:19:00 +02:00
## Environment Variables
2015-02-12 03:22:36 +01:00
Several environment variables are available for you to configure Compose's behaviour.
2014-10-03 17:19:00 +02:00
2015-01-19 06:46:23 +01:00
Variables starting with `DOCKER_` are the same as those used to configure the
2015-06-10 15:37:12 +02:00
Docker command-line client. If you're using boot2docker, `eval "$(boot2docker shellinit)"`
2015-01-19 06:46:23 +01:00
will set them to their correct values.
2014-10-16 17:35:20 +02:00
2015-02-18 12:39:57 +01:00
### COMPOSE\_PROJECT\_NAME
2014-10-03 17:19:00 +02:00
2015-02-12 03:22:36 +01:00
Sets the project name, which is prepended to the name of every container started by Compose. Defaults to the `basename` of the current working directory.
2014-10-03 17:19:00 +02:00
2015-02-18 12:39:57 +01:00
### COMPOSE\_FILE
2014-10-03 17:19:00 +02:00
2015-03-31 22:21:04 +02:00
Specify what file to read configuration from. If not provided, Compose will look
for `docker-compose.yml` in the current working directory, and then each parent
directory successively, until found.
2014-10-03 17:19:00 +02:00
2014-10-06 12:57:41 +02:00
### DOCKER\_HOST
2014-10-03 17:19:00 +02:00
2015-02-12 03:22:36 +01:00
Sets the URL of the docker daemon. As with the Docker client, defaults to `unix:///var/run/docker.sock` .
2014-10-16 17:35:20 +02:00
### DOCKER\_TLS\_VERIFY
2015-01-19 06:46:23 +01:00
When set to anything other than an empty string, enables TLS communication with
the daemon.
2014-10-16 17:35:20 +02:00
### DOCKER\_CERT\_PATH
2015-02-12 03:22:36 +01:00
Configures the path to the `ca.pem` , `cert.pem` , and `key.pem` files used for TLS verification. Defaults to `~/.docker` .
2015-02-25 09:43:33 +01:00
## Compose documentation
2015-02-12 03:22:36 +01:00
2015-06-16 05:52:55 +02:00
- [User guide ](/ )
2015-05-12 13:44:43 +02:00
- [Installing Compose ](install.md )
- [Get started with Django ](django.md )
- [Get started with Rails ](rails.md )
- [Get started with Wordpress ](wordpress.md )
2015-02-23 04:56:13 +01:00
- [Yaml file reference ](yml.md )
2015-02-25 09:43:33 +01:00
- [Compose environment variables ](env.md )
- [Compose command line completion ](completion.md )