// --scale web=5 を指定 $ docker-compose up -d --scale web=5 web 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. Starting hoge_web_1_c74182e5a539 ... done Creating hoge_web_2_13bb1a332458 ... done Creating hoge_web_3_225eac9f629c ... done Creating hoge_web_4_c27993395577 ... done Creating hoge_web_5_70bc29594f3e ... done
// ポート確認(ポートがymlに指定した範囲内で割り当てられている) $ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 42e5eaa4d2ca nginx:alpine "/usr/sbin/nginx -g …" 12 seconds ago Up 10 seconds 0.0.0.0:10083->80/tcp hoge_web_4_6d1d9b1012c3 6bcb67358dad nginx:alpine "/usr/sbin/nginx -g …" 12 seconds ago Up 9 seconds 0.0.0.0:10084->80/tcp hoge_web_2_182925f26775 84f9deee96b5 nginx:alpine "/usr/sbin/nginx -g …" 12 seconds ago Up 10 seconds 0.0.0.0:10082->80/tcp hoge_web_5_b8faed640b87 9022a4e4e4fc nginx:alpine "/usr/sbin/nginx -g …" 12 seconds ago Up 10 seconds 0.0.0.0:10081->80/tcp hoge_web_3_8eaf171dc2e7 748617fa2e75 nginx:alpine "/usr/sbin/nginx -g …" About a minute ago Up About a minute 0.0.0.0:10080->80/tcp hoge_web_1_c74182e5a539
// 3台にスケール(新しい物から順に?stopとrmされる) $ docker-compose up -d --scale web=3 web 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. Stopping and removing hoge_web_4_6d1d9b1012c3 ... done Stopping and removing hoge_web_5_b8faed640b87 ... done Starting hoge_web_1_c74182e5a539 ... done Starting hoge_web_2_182925f26775 ... done Starting hoge_web_3_8eaf171dc2e7 ... done
// ポート確認 $ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 6bcb67358dad nginx:alpine "/usr/sbin/nginx -g …" About a minute ago Up About a minute 0.0.0.0:10084->80/tcp hoge_web_2_182925f26775 9022a4e4e4fc nginx:alpine "/usr/sbin/nginx -g …" About a minute ago Up About a minute 0.0.0.0:10081->80/tcp hoge_web_3_8eaf171dc2e7 748617fa2e75 nginx:alpine "/usr/sbin/nginx -g …" 2 minutes ago Up 2 minutes 0.0.0.0:10080->80/tcp hoge_web_1_c74182e5a539
11台にスケール
冒頭でymlに指定した、portsの範囲外までスケールさせてみるとどうでしょうか
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
$ docker-compose up -d --scale web=11 web 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. Starting hoge_web_1_c74182e5a539 ... done Starting hoge_web_2_182925f26775 ... done Starting hoge_web_3_8eaf171dc2e7 ... done Starting hoge_web_4_e08618e39e12 ... done Starting hoge_web_5_71f2ef02ddad ... done Starting hoge_web_6_66bf84908909 ... done Starting hoge_web_7_46f71cd3488a ... done Starting hoge_web_8_29a1dbcd2d85 ... done Starting hoge_web_9_dd345e23b434 ... done Starting hoge_web_10_d34088bf19cd ... done Creating hoge_web_11_2e0fb2efdd37 ... error
ERROR: for hoge_web_11_2e0fb2efdd37 Cannot start service web: driver failed programming external connectivity on endpoint hoge_web_11_2dd5a27ceb24 (e72dbf1c2fac14fb47fdf3cfd702ebb1dac849a0ed6c6569511793562a6c5103): all ports are allocated
ERROR: for web Cannot start service web: driver failed programming external connectivity on endpoint hoge_web_11_2dd5a27ceb24 (e72dbf1c2fac14fb47fdf3cfd702ebb1dac849a0ed6c6569511793562a6c5103): all ports are allocated ERROR: Encountered errors while bringing up the project.