1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242
| version services build context dockerfile args cache_from labels shm_size command configs cgroup_parent container_name credential_spec deploy endpoint_mode vip dnsrr labels mode global replicated placement replicas resources limits cpus: "0.5" memory: 50M reservations cpus: "0.2" memory: 20M restart_policy condition none on-failure any delay max_attempts window update_config parallelism delay failure_action continue rollback pause monitor max_failure_ratio order stop-first start-first rollback_config parallelism delay failure_action continue pause monitor max_failure_ratio order stop-first start-first 注意: 支持 docker-compose up 和 docker-compose run 但不支持 docker stack deploy 的子选项 security_opt container_name devices tmpfs stop_signal links cgroup_parent network_mode external_links restart build userns_mode sysctls devices depends_on 示例: docker-compose up 以依赖顺序启动服务,下面例子中 redis 和 db 服务在 web 启动前启动 默认情况下使用 docker-compose up web 这样的方式启动 web 服务时,也会启动 redis 和 db 两个服务,因为在配置文件中定义了依赖关系
version: '3' services: web: build: . depends_on: - db - redis redis: image: redis db: image: postgres dns dns_search tmpfs entrypoint env_file 文件格式: RACK_ENV=development environment expose external_links
extra_hosts healthcheck test NONE CMD CMD-SHELL interval: 1m30s timeout: 10s retries: 3 start_period: 40s disable: true image init isolation labels links logging driver options max-size max-file network_mode networks aliases ipv4_address ipv6_address 示例: version: '3.7' services: test: image: nginx:1.14-alpine container_name: mynginx command: ifconfig networks: app_net: ipv4_address: 172.16.238.10 networks: app_net: driver: bridge ipam: driver: default config: - subnet: 172.16.238.0/24 pid: 'host' ports SHORT 语法格式示例: - "3000" - "3000-3005" - "8000:8000" - "9090-9091:8080-8081" - "127.0.0.1:8001:8001" - "127.0.0.1:5000-5010:5000-5010" - "6060:6060/udp"
LONG 语法格式示例:(v3.2 新增的语法格式) ports: - target: 80 published: 8080 protocol: tcp mode: host secrets security_opt
stop_grace_period
stop_signal
sysctls
ulimits
userns_mode
volumes SHORT 语法格式示例: volumes: - /var/lib/mysql - /opt/data:/var/lib/mysql - ./cache:/tmp/cache - ~/configs:/etc/configs/:ro - datavolume:/var/lib/mysql
LONG 语法格式示例:(v3.2 新增的语法格式) version: "3.2" services: web: image: nginx:alpine ports: - "80:80" volumes: - type: volume source: mydata target: /data volume: nocopy: true - type: bind source: ./static target: /opt/app/static read_only: true volumes: mydata:
restart no always on-failure
其他选项: domainname, hostname, ipc, mac_address, privileged, read_only, shm_size, stdin_open, tty, user, working_dir 上面这些选项都只接受单个值和 docker run 的对应参数类似
对于值为时间的可接受的值: 2.5s 10s 1m30s 2h32m 5h34m56s
时间单位: us, ms, s, m, h
对于值为大小的可接受的值: 2b 1024kb 2048k 300m 1gb
单位: b, k, m, g 或者 kb, mb, gb
networks driver bridge overlay host none
driver_opts
attachable
ipam driver config subnet
external
name
|