Docker 中 YML 文件是什么?
Docker中YML文件一般是指Docker默认的模板文件“docker-compose.yml”,该文件用来定义的每个服务都必须通过image指令指定镜像,或使用Dockerfile的build指令进行自动构建。
Compose文件
Compose文件是一个定义服务services、网络networks和卷volumes的YAML文件,默认路径是./docker-compose.yml,可使用.yml或.yaml作为文件扩展名。
服务services定义包含应用于为该服务启动的每个容器的配置,类似传递命令行参数一样docker container create。同样,网络networks和卷volumes的定义类似于docker network create和docker volume create。正如docker container create在Dockerfile指定选项,如CMD、EXPOSE、VOLUME、ENV,在默认情况下,不需要在docker-compose.yml配置中再次指定。可以使用Bash类${VARIABLE}语法在配置值中使用环境变量。
version: "3" services: redis: image: redis:alpine ports: - "6379" networks: - frontend deploy: replicas: 2 update_config: parallelism: 2 delay: 10s restart_policy: condition: on-failure db: image: postgres:9.4 volumes: - db-data:/var/lib/postgresql/data networks: - backend deploy: placement: constraints: [node.role == manager] vote: image: dockersamples/examplevotingapp_vote:before ports: - 5000:80 networks: - frontend depends_on: - redis deploy: replicas: 2 update_config: parallelism: 2 restart_policy: condition: on-failure result: image: dockersamples/examplevotingapp_result:before ports: - 5001:80 networks: - backend depends_on: - db deploy: replicas: 1 update_config: parallelism: 2 delay: 10s restart_policy: condition: on-failure worker: image: dockersamples/examplevotingapp_worker networks: - frontend - backend deploy: mode: replicated replicas: 1 labels: [APP=VOTING] restart_policy: condition: on-failure delay: 10s max_attempts: 3 window: 120s placement: constraints: [node.role == manager] visualizer: image: dockersamples/visualizer:stable ports: - "8080:8080" stop_grace_period: 1m30s volumes: - "/var/run/docker.sock:/var/run/docker.sock" deploy: placement: constraints: [node.role == manager] networks: frontend: backend: volumes: db-data:
推荐教程:《Docker》
Atas ialah kandungan terperinci Docker 中 YML 文件是什么?. Untuk maklumat lanjut, sila ikut artikel berkaitan lain di laman web China PHP!