demo

  1. version: '3'
  2. services:
  3. zookeeper:
  4. image: wurstmeister/zookeeper
  5. ports:
  6. - "2181:2181"
  7. kafka:
  8. image: wurstmeister/kafka
  9. depends_on: [ zookeeper ]
  10. ports:
  11. - "9092:9092"
  12. environment:
  13. KAFKA_ADVERTISED_HOST_NAME: 192.168.199.224
  14. KAFKA_CREATE_TOPICS: "test:1:1"
  15. KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
  16. volumes:
  17. - /var/run/docker.sock:/var/run/docker.sock
  18. - /etc/localtime:/etc/localtime # kafka镜像和宿主机器之间时间保持一致!!!

env功能 ( 可脚本动态控制环境,需要source脚本

  1. #!/bin/bash
  2. export IMAGETAG=web:v1
  3. export APPNAME=HelloWorld
  4. export VERSION=1.0

yml中……

  1. environment:
  2. APPNAME:
  3. APPVERSION: ${VERSION}

volumes — 将主机的数据卷或者文件挂载到容器

  1. volumes:
  2. - "/localhost/postgres.sock(本地):/var/run/postgres/postgres.sock"(容器内)

deploy:

  1. restart_policy:
  2. condition: on-failure none on-failure 以及 any(默认)
  3. delay: 5s 尝试重启的等待时间
  4. max_attempts: 3 放弃之前尝试重新启动容器次数
  5. window: 120s 在决定重新启动是否成功之前的等时间