docker compose up Command
The docker compose up command is used to start all service containers defined in a Docker Compose project, and ensure 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, --detachRun the container in background mode, similar to indocker runused in-dOptions.--build: Force rebuild images before startup, even if the images already exist.--no-build: Prevent building images at startup, even if they do not exist.--force-recreate: Force recreate containers, even if they already exist and their contents have not changed.--no-recreate: If containers already exist, do not recreate them (the default behavior is to recreate them if the configuration file changes).--remove-orphans: Remove orphan containers that are no longer defined in the Compose file.-V, --renew-anon-volumes: Recreate anonymous volumes (delete old volumes and create new ones).
Example
1. Start all services and attach to the console.
docker compose up
Start all services defined in the Compose file and display log output in the current terminal.
2. Run the service in background mode
docker compose up -d
Run all services in the background (detached) mode, and the terminal will not output service logs.
3. Start only the specified service
docker compose up web
Start only the web service, without starting other services.
4. Start services and force rebuild of images
docker compose up --build
Force rebuild the service images before starting the services.
5. Start services and force recreate containers.
docker compose up --force-recreate
Force recreate service containers, even if the previous containers exist and have not changed.
6. Start services and remove orphan containers that no longer exist in the Compose file.
docker compose up --remove-orphans
Remove any containers that are no longer defined in the current docker-compose.yml file.
other extensions