version: '3'
services:
app01:
build:
context: ./dir # 包含 Dockerfile 或者 Git 的URL
dockerfile: Dockerfile-alternate # 指定 Dockerfile 文件
args: # 指定仅仅在 Build 期间需要用的环境变量
buildno: 1 # 也可以使用 - buildno=1 或者 - buildno,后者表示直接取系统环境变量的值
cache_from: # v3.2 新特性,缓存解决方案
- alpine:latest
- corp/web_app:3.14
labels: # v3.3 新特性,增加一些元属性
com.example.description: "Accounting webapp"
com.example.department: "Finance"
com.example.label-with-empty-value: ""
command: bundle exec thin -p 3000 # 执行的命令
container_name: my-web-container
deploy: # 仅在部署到 swarm 的时候生效,这里面都是配置 服务的选项,而非 container
replicas: 6 # 如果服务时 replicated,那么可以用来配置最小运行数量。
update_config:
parallelism: 2
delay: 10s
restart_policy:
condition: on-failure
endpoint_mode: vip # v3.3 新特性,服务发现 vip/dnsrr
mode: global # global/replicated 两个模式
depends_on: # 绑定依赖关系
- db
- redis
dns_search:
- dc1.example.com # 定制依赖关系
tmpfs: # 挂载临时文件系统
- /run
entrypoint: /code/entrypoint.sh # 不知道干什么用的
env_file: # 添加一个指定环境变量的文件
- ./common.env # 文件格式为:VAR=1
environment:
- RAILS_ENV=development # 少数变量可以以这种方式指定
expose: # 暴露端口给指定的连接容器
- "3000"
- "3001"
ports: # 绑定宿主机的端口
- "3000"
- "3001"
extra_hosts: # 添加 host 映射
- "somehost:162.242.195.82"
- "otherhost:50.31.209.229"
healthcheck: # 配置一个健康检查
test: ["CMD", "curl", "-f", "http://localhost"]
interval: 1m30s
timeout: 10s
retries: 3
start_period: 40s
# disable: true # 关闭健康检查
image: ubuntu:14.04 # 指定创建容器的镜像,如果镜像不存在会自动pull,除非指定了 build
init: /usr/libexec/docker-init # v3.7新特性,执行一个初始化
labels: # 不知道有啥用
- "xxx=sdfdslabels"
links: # 连接到另一个服务的容器,它也具备 depends_on 的功能。在同一个网络中,其他也不需要进行绑定。
- db
- db:database
volumes: # 可以直接路径挂载,也可以用顶层定义的volumes别名挂载。比如 dbdata
- "/var/run/postgres/postgres.sock:/var/run/postgres/postgres.sock"
- "dbdata:/var/lib/postgresql/data"
stop_signal: SIGUSR1 # 指定停止时发送的进行信号,默认是 SINAL_TERMINAL#15,这是很安全的,所以默认即可。
restart: no # 可以指定 no/always/on-failure/unless-stopped
networks: # 添加网络
- some-network
- other-network
volumes: # 全局的硬盘绑定,适合数据共享的情况。
mydata: /data/mydata
dbdata: /data/dbdata