Files
chill_notes/Docker/安装docker-compose.md
2026-04-21 20:00:16 +08:00

71 lines
1.3 KiB
Markdown
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 安装 Docker Compose
## 方式一:作为容器运行(推荐)
Docker Compose 可以作为容器运行,通过一个轻量级 bash 脚本调用。
```bash
# 下载并安装
sudo curl -L --fail \
https://github.com/docker/compose/releases/download/v2.24.0/docker-compose-$(uname -s)-$(uname -m) \
-o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
# 验证安装
docker-compose --version
```
## 方式二pip 安装
```bash
pip install docker-compose
```
## 方式三standalone 二进制
```bash
# 下载指定版本
COMPOSE_VERSION=$(curl -s https://api.github.com/repos/docker/compose/releases/latest | grep tag_name | cut -d'"' -f4)
curl -L \
"https://github.com/docker/compose/releases/download/${COMPOSE_VERSION}/docker-compose-$(uname -s)-$(uname -m)" \
-o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
```
## 快速使用
```yaml
# docker-compose.yml 示例
version: '3.8'
services:
web:
image: nginx:latest
ports:
- "80:80"
db:
image: postgres:13
environment:
POSTGRES_PASSWORD: secret
```
```bash
# 启动服务
docker-compose up -d
# 查看状态
docker-compose ps
# 查看日志
docker-compose logs -f
# 停止服务
docker-compose down
```
---
> 参考:[Docker Compose 官方文档](https://docs.docker.com/compose/)