0
0
Dockerdevops~10 mins

docker compose up and down - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - docker compose up and down
Start: docker-compose.yml file ready
Run: docker compose up
Docker reads config
Create and start containers
Containers running
Run: docker compose down
Stop and remove containers
Cleanup networks (volumes w/ --volumes)
All stopped and cleaned
This flow shows how docker compose up starts containers from the config, and docker compose down stops and cleans them.
Execution Sample
Docker
docker compose up
# Starts containers

docker compose down
# Stops and removes containers
This code starts containers defined in docker-compose.yml, then stops and removes them.
Process Table
StepCommandActionResultState Change
1docker compose upReads docker-compose.ymlConfiguration loadedReady to create containers
2docker compose upCreates containersContainers createdContainers exist but not running
3docker compose upStarts containersContainers runningContainers running
4docker compose upOutput logsShows container logsRunning state visible
5docker compose downStops containersContainers stoppedContainers stopped
6docker compose downRemoves containersContainers removedNo containers exist
7docker compose downRemoves networks (volumes w/ --volumes)Cleanup doneNo networks remain (volumes persist by default)
💡 All containers stopped and removed, environment cleaned up (volumes persist unless --volumes)
Status Tracker
ResourceStartAfter 'up' commandAfter 'down' command
ContainersNoneCreated and runningRemoved
NetworksNoneCreatedRemoved
VolumesNoneCreated if definedRemoved if defined w/ --volumes
Key Moments - 3 Insights
Why do containers still exist after 'docker compose up' but before 'docker compose down'?
Because 'docker compose up' creates and starts containers, so they exist and run until 'docker compose down' stops and removes them, as shown in steps 3 and 5 of the execution table.
Does 'docker compose down' delete volumes by default?
No, volumes are only removed if you add the --volumes flag. The execution table and variable_tracker show volumes handling.
What happens if you run 'docker compose up' again while containers are running?
Docker Compose will detect running containers and recreate or reuse them depending on changes, but this is beyond the simple up/down flow shown here.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is the state of containers after step 3?
AContainers are removed
BContainers are stopped
CContainers are running
DContainers are created but not running
💡 Hint
Check the 'Result' and 'State Change' columns at step 3 in the execution table
At which step do containers get removed?
AStep 4
BStep 6
CStep 2
DStep 1
💡 Hint
Look for the action 'Removes containers' in the execution table
If you want volumes to be removed with 'docker compose down', what should you do?
AAdd the --volumes flag to the down command
BNothing, volumes are removed by default
CRun 'docker compose up' again
DManually delete volumes after down
💡 Hint
Refer to the key moment about volume removal and the variable_tracker row for Volumes
Concept Snapshot
docker compose up: Reads config, creates, and starts containers
Containers run and logs show

docker compose down: Stops and removes containers
Removes networks and optionally volumes
Use --volumes flag to remove volumes
Simple way to start and clean multi-container apps
Full Transcript
Docker Compose uses a file called docker-compose.yml to define containers. When you run 'docker compose up', Docker reads this file, creates the containers, and starts them. You will see logs from the containers as they run. The containers keep running until you stop them. To stop and clean up, you run 'docker compose down'. This command stops the containers, removes them, and cleans up networks and optionally volumes if you add the --volumes flag. This process helps manage multi-container applications easily by starting and stopping all parts together.