dockercomposescale的时候解决端口冲突问题
比如这个情况, 希望扩展多几个docker,但是简单scale,5000宿主机端口冲突,文件docker-compose.yml配置如下:
version: "3"
services:
my_server:
image: daocloud.io/******
ports:
- "10105:10805"
volumes:
- /usr/local/server/config:/server/config
- /usr/local/server/log:/server/log
sysctls:
- net.core.somaxconn=4096
restart: always
方法1: 动态分配端口
ports 行改成 - “10805”
docker-compose up --scale my_server=3 然后ps,此时才能知道3个宿主机端口
方法2: 加nginx,配置文件
user nginx;
events {
worker_connections 1000;
}
http {
server {
listen 4000;
location / {
proxy_pass http://my_server:10805;
}
}
}
version: "3"
services:
my_server:
image: daocloud.io/****
expose:
- 10805
volumes:
- /usr/local/server/config:/server/config
- /usr/local/server/log:/server/log
sysctls:
- net.core.somaxconn=4096
restart: always
nginx:
image: nginx:latest
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf
depends_on:
- my_server
ports:
- "10105:4000"
docker-compose up --scale my_servert=5后,nginx监听4000, 把10805的proxy pass过去.
以上是 dockercomposescale的时候解决端口冲突问题 的全部内容, 来源链接: utcz.com/z/518845.html