このドキュメントで説明されているソフトウェアはサポートされていないか、拡張サポートが提供されています。
現在サポートされているリリースにアップグレードすることをお薦めします。
レプリカ・コンテナ・インスタンスをサービスに追加したり、削除したりすることで、いつでもサービスを拡張して需要を満たすことができます。 これは、任意のマネージャ・ノードでdocker service scaleコマンドを使用して行います:
# docker service scale SERVICE
=REPLICAS
SERVICE
をスケーリングするサービスの名前またはIDに置き換え、REPLICAS
をサービスで実行するレプリカ・コンテナ・インスタンスの数で置き換えます。 次に例を示します。
# docker service scale hello=12 hello scaled to 12 # docker service ps hello ID NAME SERVICE IMAGE LAST STATE DESIRED STATE NODE 5u710ts...weir0v hello.1 hello nginxdemos/hello Running 17 minutes Running ol1.example.com b1nqbkp...65qj3f hello.2 hello nginxdemos/hello Running 17 minutes Running ol3.example.com 00hmy0p...b4kgsp hello.3 hello nginxdemos/hello Running 17 minutes Running ol4.example.com 8pv15jy...u75oz2 hello.4 hello nginxdemos/hello Running 3 seconds Running ol2.example.com cqyffbs...3w0m54 hello.5 hello nginxdemos/hello Running 4 seconds Running ol1.example.com 4pggall...b0yek3 hello.6 hello nginxdemos/hello Running 4 seconds Running ol4.example.com 9kdsm5q...ybanef hello.7 hello nginxdemos/hello Running 4 seconds Running ol3.example.com 44rebto...dygv6e hello.8 hello nginxdemos/hello Running 4 seconds Running ol3.example.com 8hoiml0...42eouu hello.9 hello nginxdemos/hello Running 4 seconds Running ol4.example.com 43ab93b...jyi194 hello.10 hello nginxdemos/hello Running 3 seconds Running ol4.example.com a7kwo7y...60gxn5 hello.11 hello nginxdemos/hello Running 3 seconds Running ol1.example.com cgg9snb...aersh4 hello.12 hello nginxdemos/hello Running 2 seconds Running ol2.example.com
この例では、hello
サービスは12個のレプリカ・コンテナを実行するようにスケーリングされています。 hello
サービスで実行されているタスクがリストされている場合、3つの元のコンテナがすでにかなり長く実行されていたのに対し、数秒間しか実行されていないため、多くの新しいコンテナが生成されています。
これらの例では、nginxdemos/hello
イメージは、サービスが特定のノードでアクセスされたときにロード・バランシング機能を実証するために使用できるので、有用です。 nginxdemos/hello
イメージには、実行中のコンテナのホスト名とIPアドレスを返すWebアプリケーションが含まれています。 swarmのノードのいずれかにWebブラウザを指定して繰り返しリフレッシュするだけで、アプリケーションによって返されたホスト名がラウンドロビン・アルゴリズムを使用して変更されることが明らかになります。 これは、curlを使用してコマンドラインに表示することもできます(例:
# curl --silent "http://ol1.example.com"|grep 'hostname' <h2>My hostname is 2a6c91061981</h2> # curl --silent "http://ol1.example.com"|grep 'hostname' <h2>My hostname is e163d77affa0</h2> # curl --silent "http://ol1.example.com"|grep 'hostname' <h2>My hostname is f4dde4ea921f</h2> # curl --silent "http://ol1.example.com"|grep 'hostname' <h2>My hostname is 2a6c91061981</h2>
サービスからコンテナ・インスタンスを削除するには、現在実行中のインスタンスの数よりも小さい数に縮小します。 この例のインスタンス数を減らすために、hello
サービスは2つのインスタンスに縮小されています:
# docker service scale hello=2 hello scaled to 2