yml文件命令
version
指定 docker-compose.yml 文件的写法格式
version: 3
services
多个容器集合
services:
image
指定服务所使用的镜像
image: postgres
environment
环境变量配置,可以用数组或字典两种方式
environment:RACK_ENV: developmentSHOW: 'ture'-------------------------environment:- RACK_ENV=development- SHOW=ture
ports
对外暴露的端口定义,和 expose 对应
ports: # 暴露端口信息 - "宿主机端口:容器暴露端口"- "8763:8763"- "8763:8763"
volumes
卷挂载路径
volumes:- /config:/ect/config
expose
暴露端口,只将端口暴露给连接的服务,而不暴露给主机
expose:- "3000"- "8000"
command
覆盖容器启动后默认执行的命令
command: bundle exec thin -p 3000----------------------------------command: [bundle,exec,thin,-p,3000]
示例
version: '3'services:server:image: postgrest/postgrestports:- "3000:3000"links:- db:dbenvironment:PGRST_DB_URI: postgres://qinyi:123456@db:5432/testPGRST_DB_SCHEMA: apiPGRST_DB_ANON_ROLE: qinyi #In production this role should not be the same as the one used for the connectionPGRST_SERVER_PROXY_URI: "http://127.0.0.1:3000"PGRST_JWT_SECRET: "oW3Fxhc07bE4vnsFzsMsnnsnb7FxSuMz"depends_on:- dbdb:image: postgresports:- "5432:5432"environment:POSTGRES_DB: testPOSTGRES_USER: rootPOSTGRES_PASSWORD: 123456# Uncomment this if you want to persist the data.volumes:- "~/postgrest/pgdata:/var/lib/postgresql/data"
常用命名
//创建docker-compose.yml文件//该文件目录下运行,-d表示后台运行docker-compose up -d//停止某个服务docker-compose stop [service_name]//某个服务,启动并重新加载docker-compose.yml文件配置docker-compose up -d --build [service_name]
