Commands - docker/compose

Docker Compose Commands

Compose is a tool for defining and running multi-container Docker applications. It uses a YAML file to configure services, and a single command to create and start all the services. Here are some of the most commonly used commands:

docker-compose up

This command creates and starts all the services defined in the Compose file. By default, it runs the services in the foreground, so you can see the output of each service.

Example:

$ docker-compose up

docker-compose down

This command stops and removes all the containers, networks, and volumes defined in the Compose file.

Example:

$ docker-compose down

docker-compose run

This command runs a single command in a new container. It’s useful for running one-off tasks, such as migrations or tests.

Example:

$ docker-compose run web python manage.py migrate

docker-compose exec

This command runs a command in a running container. It’s useful for debugging or making changes to a running service.

Example:

$ docker-compose exec web python manage.py shell

docker-compose logs

This command shows the output of the services defined in the Compose file. By default, it shows the output of all the services, but you can filter the output by service name.

Example:

$ docker-compose logs web

docker-compose ps

This command shows the status of the services defined in the Compose file.

Example:

$ docker-compose ps

docker-compose build

This command builds or rebuilds the images defined in the Compose file.

Example:

$ docker-compose build

docker-compose stop

This command stops the services defined in the Compose file.

Example:

$ docker-compose stop

docker-compose start

This command starts the services defined in the Compose file.

Example:

$ docker-compose start

docker-compose restart

This command restarts the services defined in the Compose file.

Example:

$ docker-compose restart

docker-compose pull

This command pulls the images defined in the Compose file.

Example:

$ docker-compose pull

docker-compose push

This command pushes the images defined in the Compose file.

Example:

$ docker-compose push

docker-compose create

This command creates the containers for the services defined in the Compose file.

Example:

$ docker-compose create

docker-compose rm

This command removes the containers for the services defined in the Compose file.

Example:

$ docker-compose rm

docker-compose images

This command lists the images used by the services defined in the Compose file.

Example:

$ docker-compose images

docker-compose kill

This command sends a SIGKILL signal to the services defined in the Compose file.

Example:

$ docker-compose kill

docker-compose pause

This command pauses the services defined in the Compose file.

Example:

$ docker-compose pause

docker-compose unpause

This command unpauses the services defined in the Compose file.

Example:

$ docker-compose unpause

docker-compose ports

This command shows the public port for a port binding.

Example:

$ docker-compose ports web

docker-compose events

This command receives real-time events from the containers.

Example:

$ docker-compose events

docker-compose config

This command parses, resolves, and renders the Compose file in a canonical format.

Example:

$ docker-compose config

docker-compose cp

This command copies files/folders between a service container and the local filesystem.

Example:

$ docker-compose cp web:/app/data .

For more information, see the official Docker Compose documentation.

Bash Shortcuts

Here are some Bash shortcuts that are useful when working with Docker Compose:

  • ctrl + a: Move cursor to start of line
  • ctrl + e: Move cursor to end of line
  • ctrl + u: Cut text before cursor
  • ctrl + k: Cut text after cursor
  • ctrl + w: Cut previous word
  • ctrl + y: Paste text from buffer
  • ctrl + t: Swap current character with previous character
  • ctrl + l: Clear screen
  • ctrl + r: Search backward through command history
  • ctrl + g: Cancel current editing command
  • ctrl + _: Undo last command
  • ctrl + x + e: Edit command in $EDITOR
  • ctrl + x + *: Expand glob/star
  • ctrl + xx: Move cursor to opposite end of line
  • ctrl + shift + c: Copy
  • ctrl + shift + v: Paste

For more information, see Bash tips for everyday at the command line.