Ultimate Guide to Docker-Compose Commands: Options & Examples
Command | Description | Example |
docker-compose up | Builds, (re)creates, starts, and attaches containers | docker-compose up |
docker-compose up -d | Starts containers in detached mode (runs in the background) | docker-compose up -d |
docker-compose up -f <file> | Uses a specific Compose file for building and running services | docker-compose up -f docker-compose.dev.yml |
docker-compose down | Stops and removes containers, networks, and volumes | docker-compose down |
docker-compose build | Builds or rebuilds services | docker-compose build |
docker-compose stop | Stops running containers without removing them | docker-compose stop |
docker-compose start | Starts containers that were previously stopped | docker-compose start |
docker-compose restart | Restarts services | docker-compose restart |
docker-compose ps | Lists the status of services | docker-compose ps |
docker-compose logs | Displays logs from containers | docker-compose logs |
docker-compose logs -f | Follows logs in real-time | docker-compose logs -f |
docker-compose exec | Executes a command inside a running container | docker-compose exec web bash |
docker-compose run | Runs a one-time command in a new container | docker-compose run web python manage.py migrate |
docker-compose rm | Removes stopped service containers | docker-compose rm |
docker-compose config | Validates and displays the Compose file configuration | docker-compose config |
docker-compose pull | Pulls images defined in the Compose file | docker-compose pull |
docker-compose up --scale <service-name>=<number> | Scales a service to the specified number of containers | docker-compose up --scale web=3 -d |
docker-compose kill | Forcefully stops containers | docker-compose kill |
docker-compose -f <file> | Uses a specific Compose file (for any command) | docker-compose -f docker-compose.test.yml up |
docker-compose -p <project-name> | Specifies a custom project name (instead of the directory name) | docker-compose -p myproject up |
docker-compose down --volumes | Stops containers and removes associated volumes | docker-compose down --volumes |
Subscribe to my newsletter
Read articles from Karthik T directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Karthik T
Karthik T
Experienced SDET with expertise in building hybrid UI & API automation frameworks using Playwright, Selenium, RestAssured and Docker ,Proficient in delivering scalable test solutions with comprehensive reporting