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 ...
随机推荐
- AMBA总线协议(一)——一文看懂APB总线协议
0.AMBA总线概括 AMBA(Advanced Microcontroller Bus Architecture) 总线是由ARM公司提出的一种开放性的片上总线标准,它独立于处理器和工艺技术,具有高 ...
- JOI Open 2018
T1 Bubble Sort 2 题意:给定一个长度为 \(n\) 的序列 \(a\),进行 \(q\) 次修改,第 \(i\) 次将第 \(x_i\) 个元素的值修改为 \(y_i\). 对于每次操 ...
- 开源的口袋妖怪自走棋「GitHub 热点速览」
作为一名 90 后,我对口袋妖怪(宝可梦)游戏有着特殊的感情,满满的都是回忆.如果你也喜欢宝可梦主题的游戏,这款开源的宝可梦自走棋游戏 pokemonAutoChess 一定要试试,它采用战棋(自走棋 ...
- 在 KubeSphere 中使用 APISIX Ingress 网关接入自定义监控
KubeSphere 3.2.0 发布了!为项目网关增配了整套监控及管理页面,同时引入了集群网关来提供集群层面全局的 Ingress 网关能力.当然,我们还是可以部署使用第三方 Ingress Con ...
- Nuxt.js 应用中的 build:manifest 事件钩子详解
title: Nuxt.js 应用中的 build:manifest 事件钩子详解 date: 2024/10/22 updated: 2024/10/22 author: cmdragon exce ...
- vue中事件总线bus的用法
./util/Bus.js import Bus from 'vue'; let install = function (Vue) { // 设置eventBus Vue.prototype.bus ...
- 轻量级网络-MobileNetv1 论文解读
1.相关工作 标准卷积 分组卷积 从 Inception module 到 depthwise separable convolutions 2.MobileNets 结构 2.1,深度可分离卷积 D ...
- k8s DockerFile中使用执行linux命令,安装字体
#字体安装 RUN apt-get update && \apt-get -y install fontconfig xfonts-utils && \mkdir -p ...
- spring需要在https下进行开发配置方法
keytool -genkey -alias tomcathttps -keyalg RSA -keysize 2048 -keystore sang.p12 -validity 365 genkey ...
- 斜率优化初探:以 [HNOI2008]玩具装箱 为例
题目传送门 记 \(f[i]\) 表示装好前 \(i\) 个的最小花费.容易写出转移: \[f[i] = \min_{j \lt i} \ [f[j]+(s[i] - s[j] - 1 - L) ^ ...