Linux command
docker-compose 命令
文本
复制后可按需替换文件名、目录或参数。
常用示例
Start
docker-compose up
Start
docker-compose up -d
Stop
docker-compose down
View
docker-compose logs
Build
docker-compose build
List
docker-compose ps
说明
docker-compose is a tool for defining and running multi-container Docker applications using YAML configuration files. Instead of managing multiple docker run commands with complex flags, Compose lets you declare your entire application stack in a single docker-compose.yml file. The tool handles service orchestration, networking, volume management, and dependencies between containers. It automatically creates isolated networks for your application, manages startup order through depends_on directives, and provides convenient commands for viewing logs, executing commands, and managing the entire application lifecycle. Docker Compose is essential for local development environments where applications require multiple services (web server, database, cache, queue). It ensures consistency across development teams and simplifies the transition from development to production. Modern Docker includes Compose V2 as a native plugin (docker compose) replacing the standalone docker-compose command.
参数
- up -d
- Create and start containers
- down
- Stop and remove containers, networks
- build
- Build or rebuild services
- start
- Start services
- stop
- Stop services
- restart
- Restart services
- ps
- List containers
- logs -f
- View output from containers
- exec _service_ _command_
- Execute command in running container
- pull
- Pull service images
- config
- Validate and view compose file
FAQ
What is the docker-compose command used for?
docker-compose is a tool for defining and running multi-container Docker applications using YAML configuration files. Instead of managing multiple docker run commands with complex flags, Compose lets you declare your entire application stack in a single docker-compose.yml file. The tool handles service orchestration, networking, volume management, and dependencies between containers. It automatically creates isolated networks for your application, manages startup order through depends_on directives, and provides convenient commands for viewing logs, executing commands, and managing the entire application lifecycle. Docker Compose is essential for local development environments where applications require multiple services (web server, database, cache, queue). It ensures consistency across development teams and simplifies the transition from development to production. Modern Docker includes Compose V2 as a native plugin (docker compose) replacing the standalone docker-compose command.
How do I run a basic docker-compose example?
Run `docker-compose up` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does up -d do in docker-compose?
Create and start containers