docker-compose.yml 使用说明
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: mydockerfileimage
指定运行容器使用的镜像。下面的格式都支持。
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.2container_name
默认运行出来的容器名。
version: '3'
services:
order-service
build: ./
image: www.myharbor.com:10080/eshop/order-service:v1.0.2
container_name: my-ordercommand
覆盖容器启动后默认执行的命令(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.pylinks
链接到其它服务中的容器。使用服务名称(同时作为别名)或服务名称:服务别名 (SERVICE:ALIAS) 格式都可以。
version: '3'
services:
order-service
links:
- user-service
- pay-service
- redisexternal_links
链接到 docker-compose.yml 外部的容器,参数格式跟 links 类似。
version: '3'
services:
order-service
external_links:
- redis_1
- project_db_1:mysql
- project_db_1:postgresqlport
暴露端口信息。
version: '3'
services:
api-gateway-ocelot
image: api-gateway-ocelot-service:latest
links:
- user-service
- eshop-service
port: 8080:8080expose
指定内部端口,但不映射到宿主机,只被连接的服务访问。
version: '3'
services:
api-gateway-ocelot
image: api-gateway-ocelot-service:latest
links:
- user-service
- eshop-service
expose: 8080environment
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.101ports
将容器的端口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:80volumes
设置容器的数据卷路径。
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-lognetworks
容器使用的网络设置。
ersion: '3'
services:
order-service
network: my-net
docker-compose.yml 使用说明的更多相关文章
- Docker Compose YML文件配置
Docker Compose YML 默认的模板文件是 docker-compose.yml,其中定义的每个服务都必须通过 image 指令指定镜像或 build 指令(需要 Dockerfile)来 ...
- docker compose yml 文件常用字段简介
常用参数: version # 指定 compose 文件的版本 services # 定义所有的 service 信息, services 下面的第一级别的 key 既是一个 service 的名称 ...
- Docker Compose yml
Wordpress + Mysql version: '3' services: db: image: mysql:latest volumes: - db_data:/var/lib/mysql e ...
- Docker Compose 创建yml 简单试例
Docker Compose 创建yml 简单试例 Docker Compose 文件使用格式版本需要与Docker版本对应可在官网内查找 查找地址:https://docs.docker.com/c ...
- docker内程序如何读取dockerfile和compose.yml中设置的环境变量
docker内程序如何读取dockerfile和compose.yml中设置的环境变量 背景 compose文件中配置了服务A和服务B,其中B服务调用了A服务的接口,那么B的实现代码中该如何调用A的服 ...
- 25.docker compose 简介 和 docker-compose.yml 参数介绍
1. docker compose概念 文档 https://docs.docker.com/compose/compose-file/compose-versioning 一个基于 docker ...
- Docker Compose部署项目到容器-基于Tomcat和mysql的项目yml配置文件代码
场景 Docker-Compose简介与Ubuntu Server 上安装Compose: https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/deta ...
- Docker Compose部署Nexus3时的docker-compose,yml代码
场景 Docker-Compose简介与Ubuntu Server 上安装Compose: https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/deta ...
- Docker Compose容器编排
Compose是Docker官方的开源项目,可以实现对Docker容器集群的快速编排.Compose 中有两个重要的概念:服务(service):一个应用的容器,实际上可以包括若干运行相同镜像的容器实 ...
- docker——三剑客之Docker Compose
编排(Orchestration)功能是复杂系统实现灵活可操作性的关键.特别是在Docker应用场景中,编排意味着用户可以灵活的对各种容器资源实现定义和管理. 作为Docker官方编排工具,Compo ...
随机推荐
- Android 内存分析(java native heap内存、虚拟内存、处理器内存.
1.jvm 堆内存(dalvik 堆内存) 每个Java应用程序在运行时都会拥有自己的JVM实例,这个实例会为其分配独立的堆内存空间.这意味着不同的应用程序之间不会共享堆内存. 不同手机中app进程的 ...
- 2021年9月国产数据库排行榜-墨天轮:达梦奋起直追紧逼OceanBase,openGauss反超PolarDB再升一位
2021年9月国产数据库排行榜已在墨天轮发布,本月参与排名的数据库总数达到了142个. 一.9月国产数据库流行度排行榜前15名 先来看看排行榜前五名,虽然PingCAP的TiDB分数本月下降31.82 ...
- yarn serve 开启项目服务失败 assets emit different content to the same filename
error: answer: 删除public的文件,重新 yarn serve :
- 015 Python 的输入输出和字符串格式化(终于可以和计算机交流了)
#!/usr/bin/env python # -*- coding:utf-8 -*- # Datatime:2022/7/26 20:11 # Filename:015 Python 的输入输出和 ...
- FFmpeg开发笔记(五十九)Linux编译ijkplayer的Android平台so库
ijkplayer是一款由B站研发的移动端国产播放器,它基于FFmpeg3.4版本,同时兼容Android和iOS两大移动操作系统.ijkplayer的源码托管地址为https://github.co ...
- .NET + 微信小程序开源多功能电商系统
前言 推荐一款基于微信小程序.LayUI 和 .NET 平台的多功能电商系统,支持二次开发和扩展,帮助大家轻松快速搭建一个功能全面且易于管理的在线商城. 项目介绍 该项目不仅包含了微信小程序前端,还配 ...
- 5道大厂的JAVA经典面试题
前言 本来想着给自己放松一下,刷刷博客,慕然回首,Java的四种引用,强弱软虚?泛型常用特点?Java创建对象有几种方式? 有没有可能两个不相等的对象有相同的hashcode?深拷贝和浅拷贝的区别是什 ...
- 第二篇:低功耗模组Air724UG硬件设计手册
接着上篇,继续分享. 3.5 串口 模块提供了五个通用异步收发器:主串口 UART1.校准串口 UART2.通用串口 UART3.调试串口 HOST UART 和 ZSP UART. 3.5.1 ...
- 服务器安全之DenyHosts
情景:今天登录服务器,突然发现登录之后展示的信息有点多,仔细端倪发现: There were 3975 failed login attempts since the last successful ...
- 奇奇怪怪的编程语言:Malbolge
Malbolge 除了我们日常使用的Python.Java.C等主流编程语言外,还存在这么一类极为晦涩难懂的编程语言,被称为深奥的编程语言(Esoteric programming language, ...