参考:https://www.cnblogs.com/JulianHuang/p/12568814.html
单台机器,多实例,场景还没遇到过,先记一下吧。
原理:利用nginx和docker内置DNS转发web接口。
version: "3"
services:
webapp:
image: "luksa/kubia"
depends_on:
- db
ports:
- "8080" # 主机Port: 容器暴露Port
nginx.conf
user nginx;
events {
worker_connections 1000;
}
http {
server {
listen 80;
location / {
proxy_pass http://webapp:8080;
}
}
}
version: "3"
services:
webapp:
image: "luksa/kubia"
nginx:
image: nginx:latest
volumes:
- type: bind
source: /home/root/test/nginx.conf
target: /etc/nginx/nginx.conf
depends_on:
- webapp
ports:
- "80:80"
:::info docker-compose up —scale webapp=3 :::
IMAGE COMMAND PORTS NAMES
luksa/kubia "node app.js" test_webapp_1
luksa/kubia "node app.js" test_webapp_3
luksa/kubia "node app.js" test_webapp_2
nginx:latest "nginx -g 'daemon of…" 0.0.0.0:80->80/tcp test_nginx_1