• 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. 2022年10月中国数据库排行榜:达梦冲刺IPO热度不减,PolarDB立足创新夺锦才

    秋风萧瑟,洪波涌起. 2022年10月的 墨天轮中国数据库流行度排行榜 火热出炉,本月共有245个数据库参与排名,相比上月新增七个数据库,本月排行榜前十名变动较大:达梦反超openGauss重摘探花: ...

  2. ES5 和 ES6 的区别,说几个 ES6 的新增方法

    ECMAscript5.,即ES5 ,表示 ECMAscript的第五次修订-2009 : ECMAscript6.,即ES6 ,表示 ECMAscript的第六次修订-2015 : ES6 是对于 ...

  3. 43.v-if和v-for的优先级

    v-for 的优先级高 延申问题:v-for 和 v-if 为什么不能在一起使用 ? 会造成性能的浪费,因为v-for 的优先级高,所以每次渲染都会执行v-if 判断条件,浪费时间 :比如 渲染 10 ...

  4. Android复习(三)清单文件中的元素——>action、activity-alias、category、compatible-screens、data

    <action> 语法: <action android:name="string" />   包含于: <intent-filter> 说明: ...

  5. what can i say?

    今天也是打了一场让我GG的考试 首先来个炸裂的: 全场唯一爆0的,堪称MVP what can i say 赛时一共交了三遍,就最后一遍GG了. 分析一下原因吧: wa的码: #include< ...

  6. 5.29 相约杭州!云原生 Meetup 第二期杭州站开启报名

    以容器技术和容器编排为基础的云原生应用,被越来越多的企业用户接受和使用,并且在生产环境中使用容器技术的比例逐年增加.KubeSphere 作为一款面向应用的开源容器混合云,经过 3 年的发展和 10 ...

  7. C#/.NET/.NET Core学习路线集合,学习不迷路!

    前言 C#..NET..NET Core.WPF.WinForm.Unity等相关技术的学习.工作路线集合(持续更新)!!! 全面的C#/.NET/.NET Core学习.工作.面试指南:https: ...

  8. PHP实现断点续传

    解释 业务上要求对资源文件进行加密,遂实现通过php接口调用,修改header头,传输流的方式. 测试中,在苹果手机上,如果文件过大(大概10M以上),会主动调用多次接口.此时如果不使用断点续传的方式 ...

  9. SSIS以yyyyMMdd的形式获取当前系统时间

    公式: (DT_WSTR,4)YEAR(GETDATE()) + RIGHT("0" + (DT_WSTR,2)MONTH(GETDATE()),2) + RIGHT(" ...

  10. nsenter 常用操作

    nsenter 是一个可以用来进入到目标程序说在 namespace 中运行命令的工具,一般可以用于在容器外 debug 容器中运行的程序.简单记录一下 nsenter 的常用用法. 常用参数 最常用 ...