• docker-compose.yml 结构

      docker-compose.yml文件分为三个主要部分:services、networks、volumes.。
      services主要用来定义各个容器。
      networks定义需要使用到的network.。
      volumes定义services使用到的volume 。

      docker-compose配置文件样板:

      可以不用docker-compose.yml命名,可以指定别的名字例如 service.yml

      version: "3"
      service:
      order-service:
      image: 192.168.0.101:10080/eshop/eshop-order:latest
      deploy:
      endpoint_mode: vip
      replicas: 3
      restart_policy:
      condition: on-failure
      resources:
      limits:
      cpus: "0.2"
      memory: 2G
      depends_on:
      - nginx-service
      - pay-service pay-service:
      image: 192.168.0.101:10080/eshop/eshop-pay:latest
      deploy:
      endpoint_mode: vip
      replicas: 3
      restart_policy:
      condition: on-failure
      resources:
      limits:
      cpus: "0.2"
      memory: 2G
      depends_on:
      - nginx-service nginx-service
      image: 192.168.0.101:10080/base/nginx
      ports:
      - "8002:80" networks:
      default:
      external:
      name: my-overlay-net

      然后用docker stack执行service.yml

      # test表示stack名
      docker stack deploy -c service.yml test

      每个服务都必须通过 image 指令指定镜像或 build 指令(需要 Dockerfile)来自动构建。如果使用 build 指令,在 Dockerfile 中设置的选项(例如:CMD, EXPOSE, VOLUME, ENV 等) 将会自动被获取,无需在 docker-compose.yml 中再次设置。

      常用命令介绍

      build

      使用当前目录下的Dockerfile进行构建。

      version: '3'
      services:
      web:
      build: ./

      build也可以指定文件路径,Dockerfile的名字.

      version: '3'
      services:
      web:
      build:
      context: ./
      dockerfile: mydockerfile

      image

      指定运行容器使用的镜像。下面的格式都支持。

      image: redis
      image: ubuntu:14.04
      image: yyee/eshop.order:latest
      image: www.myharbor.com:10080/eshop/eshop.order:latest
      image: eshop:latest

      如果本地不存在指定的镜像,则会从repository pull下来。

      version: '3'
      services:
      order-service
      build: ./
      image: www.myharbor.com:10080/eshop/order-service:v1.0.2

      container_name

      默认运行出来的容器名。

      version: '3'
      services:
      order-service
      build: ./
      image: www.myharbor.com:10080/eshop/order-service:v1.0.2
      container_name: my-order

      command

      覆盖容器启动后默认执行的命令(Dockerfile定义的CMD)。当Dockerfile定义了entrypoint的时候,docker-comose.yml定义的command会被覆盖。

      version: '3'
      services:
      web:
      build: ./
      command: ["dotnet","eshop.order.dll"]

      entrypoint

      可以覆盖Dockerfile中定义的entrypoint命令。

      version: '3'
      services:
      web:
      build: ./
      entrypoint: python app.py

      links

      链接到其它服务中的容器。使用服务名称(同时作为别名)或服务名称:服务别名 (SERVICE:ALIAS) 格式都可以。

      version: '3'
      services:
      order-service
      links:
      - user-service
      - pay-service
      - redis

      external_links

      链接到 docker-compose.yml 外部的容器,参数格式跟 links 类似。

      version: '3'
      services:
      order-service
      external_links:
      - redis_1
      - project_db_1:mysql
      - project_db_1:postgresql

      port

      暴露端口信息。

      version: '3'
      services:
      api-gateway-ocelot
      image: api-gateway-ocelot-service:latest
      links:
      - user-service
      - eshop-service
      port: 8080:8080

      expose

      指定内部端口,但不映射到宿主机,只被连接的服务访问。

      version: '3'
      services:
      api-gateway-ocelot
      image: api-gateway-ocelot-service:latest
      links:
      - user-service
      - eshop-service
      expose: 8080

      environment

      enviroment定义的变量会覆盖.env文件中定义的重名环境变量。

      environment:
      RACK_ENV: development
      SHOW: 'true'
      BASEAPI_URL: 192.168.0.101 # 或者 environment:
      - RACK_ENV=development
      - SHOW=true
      - BASEAPI_URL=192.168.0.101

      ports

      将容器的端口80映射到宿主机的端口8080

      version: '3'
      services:
      api-gateway-ocelot
      image: api-gateway-ocelot-service:latest
      links:
      - user-service
      - eshop-service
      ports: 8080 # 或者
      version: '3'
      services:
      api-gateway-ocelot
      image: api-gateway-ocelot-service:latest
      links:
      - user-service
      - eshop-service
      ports:
      - 8080:80
      - 127.0.0.1:8080:80

      volumes

      设置容器的数据卷路径。

      version: '3'
      services:
      order-service
      build: ./
      image: www.myharbor.com:10080/eshop/order-service:v1.0.2
      ontainer_name: my-order
      values:
      - data_path: /var/data/order-data
      - log-path:/ var/data/order-log

      networks

      容器使用的网络设置。

      ersion: '3'
      services:
      order-service
      network: my-net
 

docker-compose.yml 使用说明的更多相关文章

  1. Docker Compose YML文件配置

    Docker Compose YML 默认的模板文件是 docker-compose.yml,其中定义的每个服务都必须通过 image 指令指定镜像或 build 指令(需要 Dockerfile)来 ...

  2. docker compose yml 文件常用字段简介

    常用参数: version # 指定 compose 文件的版本 services # 定义所有的 service 信息, services 下面的第一级别的 key 既是一个 service 的名称 ...

  3. Docker Compose yml

    Wordpress + Mysql version: '3' services: db: image: mysql:latest volumes: - db_data:/var/lib/mysql e ...

  4. Docker Compose 创建yml 简单试例

    Docker Compose 创建yml 简单试例 Docker Compose 文件使用格式版本需要与Docker版本对应可在官网内查找 查找地址:https://docs.docker.com/c ...

  5. docker内程序如何读取dockerfile和compose.yml中设置的环境变量

    docker内程序如何读取dockerfile和compose.yml中设置的环境变量 背景 compose文件中配置了服务A和服务B,其中B服务调用了A服务的接口,那么B的实现代码中该如何调用A的服 ...

  6. 25.docker compose 简介 和 docker-compose.yml 参数介绍

    1. docker compose概念 文档  https://docs.docker.com/compose/compose-file/compose-versioning 一个基于 docker ...

  7. Docker Compose部署项目到容器-基于Tomcat和mysql的项目yml配置文件代码

    场景 Docker-Compose简介与Ubuntu Server 上安装Compose: https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/deta ...

  8. Docker Compose部署Nexus3时的docker-compose,yml代码

    场景 Docker-Compose简介与Ubuntu Server 上安装Compose: https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/deta ...

  9. Docker Compose容器编排

    Compose是Docker官方的开源项目,可以实现对Docker容器集群的快速编排.Compose 中有两个重要的概念:服务(service):一个应用的容器,实际上可以包括若干运行相同镜像的容器实 ...

  10. docker——三剑客之Docker Compose

    编排(Orchestration)功能是复杂系统实现灵活可操作性的关键.特别是在Docker应用场景中,编排意味着用户可以灵活的对各种容器资源实现定义和管理. 作为Docker官方编排工具,Compo ...

随机推荐

  1. Oracle数据库安装配置详细教程汇总(含11g、12c、18c、19c、21c)

    不论你是数据库小白,还是久经沙场的技术专家,你接触和运维Oracle数据库的第一步可能都是安装配置.并且随着软硬件的升级.替换以及业务场景的变化,数据库安装也将是你常常会进行的操作之一. 这里先为大家 ...

  2. 墨天轮沙龙 | 腾讯云陈昊:TDSQL-C Serverless应用与技术实践

    导读 数据库的发展由对性能的要求,逐步发展为对更为极致成本的要求,Serverless数据库是在高性能云数据库之上的极致成本优化方案.[墨天轮数据库沙龙-Serverless专场]邀请到腾讯云数据库产 ...

  3. 本地图片上传服务器返回在线地址接口 - file - input -修改头像-带预览功能- 然后使用cropperjs 进行裁剪

    说明:上传的图片是 file 类型 ,核心就是获取图片文件(file类型的) : 实现一:使用 vant2 的图片加载组件 ,选择文件后会触发afterRead方法 ,参数 file 就是文件列表fi ...

  4. Machine Learning Week_1 Introduction 1-4

    目录 1 Introduction 1.1 Video: Welcome unfamiliar words symbols 1.2 Video: What is machine learning? u ...

  5. Linux利用crontab命令定时任务

    系统配置文件/etc 系统周期性所要执行的工作,比如写缓存数据到硬盘.日志清理等.在/etc目录下有一个crontab文件,这个就是系统任务调度的配置文件. /etc/crontab文件大概包括下面几 ...

  6. switch、case语句的问题

    switch.case语句: 点击查看代码 int state = 1; switch(state) { case 1: { //状态1执行的程序 } case 2: { //状态2执行的程序 } d ...

  7. CF716B Complete the Word 题解

    CF716B Complete the Word 题解 分析 首先观察数据范围是 \(50000\),可以考虑 \(O(n)\) 暴力. 在字符串中枚举子串开始的位置 \(i\),然后再枚举 \(i\ ...

  8. .NET Core 委托底层原理浅谈

    简介 .NET通过委托来提供回调函数机制,与C/C++不同的是,委托确保回调是类型安全,且允许多播委托.并支持调用静态/实例方法. 简单来说,C++的函数指针有如下功能限制,委托作为C#中的上位替代, ...

  9. Air780E如何发送SMS?一文详解!

    ​ 今天一起来学习使用合宙低功耗4G模组Air780E发送SMS短消息: 一.SMS简介 SMS(短消息服务,ShortMessageService)功能主要用于在蜂窝网络中传输短消息. 在4G网络中 ...

  10. 2024-11-20:交替子数组计数。用go语言,给定一个二进制数组 nums, 如果一个子数组中的相邻元素的值都不相同,我们称这个子数组为交替子数组。 请返回数组 nums 中交替子数组的总数。 输

    2024-11-20:交替子数组计数.用go语言,给定一个二进制数组 nums, 如果一个子数组中的相邻元素的值都不相同,我们称这个子数组为交替子数组. 请返回数组 nums 中交替子数组的总数. 输 ...