docker compose up command
The docker compose up command starts all service containers defined in a Docker Compose project and ensures they run according to the configuration in the docker-compose.yml file.
The docker compose up command not only starts services but also automatically builds images that have not been built yet (if necessary), creates networks and volumes, and starts services as containers.
Syntax
docker compose up [OPTIONS] [SERVICE...]
- SERVICE(Optional): You can specify one or more services to start only those services. If not specified, all services will be started.
OPTIONS:
-d, --detach: Runs containers in detached mode, similar to running them in thedocker runUsing it in-doption.--build: Forces images to be rebuilt before starting, even if they already exist.--no-build: Prevents building images at startup, even if they do not exist.--force-recreate: Forces containers to be recreated even if they already exist and have not changed.--no-recreate: Does not recreate containers if they already exist (the default behavior is to recreate if the configuration file has changed).--remove-orphans: Removes orphaned containers that are no longer defined in the Compose file.-V, --renew-anon-volumes: Recreates anonymous volumes (removes old volumes and creates new ones).
Example
1. Start all services and attach to the console
docker compose up
Starts all services defined in the Compose file and displays log output in the current terminal.
2. Run services in background mode
docker compose up -d
Runs all services in background (detached) mode; the terminal will not output service logs.
** 3. Start only specified services**
docker compose up web
Only starts the web service, not other services.
** 4. Start services and force image rebuild**
docker compose up --build
Forces service images to be rebuilt before starting services.
** 5. Start services and force container recreation**
docker compose up --force-recreate
Forces service containers to be recreated even if previous containers exist and have not changed.
6. Start services and remove orphaned containers no longer in the Compose file
docker compose up --remove-orphans
Removes any containers no longer defined in the current docker-compose.yml file.
Docker Command Reference