docker compose up creates and starts the services declared in a Compose file. Run it from the application directory; use docker compose up -d to keep services running in detached mode. section 6.2.2 section 7.3.3
Use related commands to control the Compose application:
- Run docker compose up to start the application in the foreground, or docker compose up -d to start it detached. section 6.2.2 section 7.3.3
- Run docker compose up --build after changing a service Dockerfile so the service image is rebuilt before startup. section 6.4.2
- Run docker compose down to stop services and clean up Compose-managed resources; use docker compose down -v when attempting to remove volumes. section 6.2.2 section 6.3.2
- Use docker compose exec service command to inspect files or run commands inside a running service without identifying its container ID. section 6.3.2
Start a Python web service
With a compose.yaml defining a web service that builds from Dockerfile, maps port 8080, and sets PORT=8080, run docker compose up. Open another terminal to run docker compose down. section 6.2.2
Start production services remotely
After copying compose.yaml and .env to a virtual machine and pulling updated images, change to the application directory and run docker compose up -d. Compose starts the production web service using its image and environment file. section 7.3.3
Listing 6.3 Docker Compose for our Python app
services:
web:
build:
context: .
dockerfile: Dockerfile
ports:
- "8080:8080"
environment:
- PORT=8080
Shows the minimal Compose configuration needed to build and start the Python web service. section 6.2.2

