docker-compose一个应用启动多个节点
一、docker-compose.yml配置
version: "2"
services:
web:
image: nginx:1.19.9-alpine
restart: always
ports:
- 80-81:80
二、启动服务
docker-compose up -d --scale web=2
Creating network "nginx_default" with the default driver
WARNING: The "web" service specifies a port on the host. If multiple containers for this service are created on a single host, the port will clash.
Creating nginx_web_1 ... done
Creating nginx_web_2 ... done
三、查看应用状态
[root@localhost nginx]# docker-compose ps
Name Command State Ports
-------------------------------------------------------------------------
nginx_web_1 /docker-entrypoint.sh ngin ... Up 0.0.0.0:80->80/tcp
nginx_web_2 /docker-entrypoint.sh ngin ... Up 0.0.0.0:81->80/tcp
四、问题处理
将80改为80-81对外映射范围,但是仍会有提示警告但不影响使用
ports:
- 80-81:80
五、升级使用方法
使用haproxy代理做负载
version: "2"
services:
web:
image: nginx:1.19.9-alpine
restart: always
lb:
image: dockercloud/haproxy
links:
- web
ports:
- 80:80