網(wǎng)站首頁 編程語言 正文
一些示例未整理
haproxy 與nginx 容器連接
## 服務(wù)的compose 編寫 mkdir /mnt/compose vim docker-compose.yml web1:? ? ? ? ? image: nginx ? ? ? ? expose:? ? ? ? ? ? ? ? ? - 80 ? ? ? ? volumes:? ? ? ? ? ? ? ? ? - ./web1:/usr/share/nginx/html web2: ? ? ? ? image: nginx ? ? ? ? expose: ? ? ? ? ? ? ? ? - 80 ? ? ? ? volumes: ? ? ? ? ? ? ? ? - ./web2:/usr/share/nginx/html haproxy: ? ? ? ? image: haproxy ? ? ? ? volumes: ? ? ? ? ? ? ? ? - ./haproxy/haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro ? ? ? ? links: ? ? ? ? ? ? ? ? - web1 ? ? ? ? ? ? ? ? - web2 ? ? ? ? ports:? ? ? ? ? ? ? ? ? - "80:80" ? ? ? ? expose: ? ? ? ? ? ? ? ? - 80 ##haproxy 配置文件 [root@server1 compose]# mkdir web1 [root@server1 compose]# mkdir web2 [root@server1 compose]# echo web1 > web1/index.html [root@server1 compose]# echo web2 > web2/index.html [root@server1 compose]# mkdir haproxy [root@server1 compose]# ls docker-compose.yml ?haproxy ?web1 ?web2 [root@server1 compose]# vim haproxy/haproxy.cfg? [root@server1 compose]# cat haproxy/haproxy.cfg? global ?? ?log 127.0.0.1 local0 ?? ?log 127.0.0.1 local1 ?notice defaults ?? ?log global ?? ?mode http ?? ?option httplog ?? ?option dontlognull ?? ?timeout connect 5000ms ?? ?timeout client 5000ms ?? ?timeout server 5000ms ?? ?stats uri /status frontend balancer ?? ?bind 0.0.0.0:80 ?? ?default backend web_backends backend web backends ?? ?balance roundrobin ?? ?server server1 web1:80 check ?? ?server server2 web2:80 check
關(guān)鍵點是如何配置容器如何互相連接
1,首先在compose 文件中指定服務(wù)名稱.然后配置links ??
2,在配置文件中指定服務(wù)的名稱
docker-compose 配置文件一些知識#
network_mode:設(shè)置網(wǎng)絡(luò)模式 network_mode: "bridge" network_mode: "host" network_mode: "none" network_mode: "service:[service name]" network_mode: "container:[container name/id]" links:將指定容器連接到當前連接,可以設(shè)置別名,避免ip方式導(dǎo)致的容器重啟動態(tài)改變的無法連接情況 links: ? ?# 指定服務(wù)名稱:別名? ? ? - docker-compose-eureka-server:compose-eureka 更新容器: 當服務(wù)的配置發(fā)生更改時,可使用 docker-compose up 命令更新配置 此時,Compose 會刪除舊容器并創(chuàng)建新容器,新容器會以不同的 IP 地址加入網(wǎng)絡(luò),名稱保持不變,任何指向舊容起的連接都會被關(guān)閉,重新找到新容器并連接上去 links 服務(wù)之間可以使用服務(wù)名稱相互訪問,links 允許定義一個別名,從而使用該別名訪問其它服務(wù) version: '2' services: ? ? web: ? ? ? ? build: . ? ? ? ? links: ? ? ? ? ? ? - "db:database" ? ? db: ? ? ? ? image: postgres
參考文章:
https://www.cnblogs.com/jackadam/p/9771718.html
https://itbilu.com/linux/docker/Ey5dT-i2G.html
原文鏈接:https://www.cnblogs.com/g2thend/p/11762173.html
相關(guān)推薦
- 2022-02-21 小程序數(shù)據(jù)延遲時,可使用userInfoReadyCallback解決
- 2023-01-15 C#實現(xiàn)虛擬鍵盤的實例詳解_C#教程
- 2023-07-27 TypeScript類和多態(tài)、抽象類、訪問修飾符
- 2022-11-20 C#設(shè)計模式之裝飾器模式實例詳解_C#教程
- 2023-03-29 goland遠程調(diào)試k8s上容器的實現(xiàn)_Golang
- 2021-11-16 linux系統(tǒng)下用戶管理相關(guān)介紹_Linux
- 2022-07-26 更新kali源并,安裝dirseach
- 2022-04-17 uniapp 實現(xiàn)無感刷新token, 適應(yīng)大多數(shù)項目
- 最近更新
-
- window11 系統(tǒng)安裝 yarn
- 超詳細win安裝深度學(xué)習(xí)環(huán)境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎(chǔ)操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區(qū)別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權(quán)
- redisson分布式鎖中waittime的設(shè)
- maven:解決release錯誤:Artif
- restTemplate使用總結(jié)
- Spring Security之安全異常處理
- MybatisPlus優(yōu)雅實現(xiàn)加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務(wù)發(fā)現(xiàn)-Nac
- Spring Security之基于HttpR
- Redis 底層數(shù)據(jù)結(jié)構(gòu)-簡單動態(tài)字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應(yīng)用詳解
- 聊聊消息隊列,發(fā)送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支