docker compose的常用配置
时间: 2023-07-25 09:05:36 浏览: 46
Docker Compose 是 Docker 官方提供的一个工具,用于定义和运行多个容器的 Docker 应用程序。以下是常用的 Docker Compose 配置:
1. version:指定 Compose 文件版本号。
2. services:定义各个服务的配置。
3. container_name:指定容器的名称。
4. image:指定容器所使用的镜像名称。
5. ports:指定容器端口映射到宿主机的端口号。
6. volumes:指定容器和宿主机之间的文件挂载关系。
7. environment:指定容器的环境变量。
8. command:指定容器启动时执行的命令。
例如:
```
version: '3'
services:
web:
container_name: my-web-app
image: nginx
ports:
- "80:80"
volumes:
- ./web:/usr/share/nginx/html
environment:
- ENVIRONMENT=production
command: nginx -g "daemon off;"
```
以上配置用于启动一个基于 Nginx 的 Web 应用,将容器的 80 端口映射到宿主机的 80 端口,将本地的 ./web 目录挂载到容器的 /usr/share/nginx/html 目录下,设置容器的环境变量为 production,启动容器时执行 nginx -g "daemon off;" 命令。