Docker-Compose Scale / Top
docker-compose scale
this command is used to scale up a number of containers, let’s say if you want to create 4 containers of webapp1 and 2 containers of webapp2 then using docker-compose scale command it can be done.
[email protected]:~/docker-compose$ cat docker-compose.yaml
version: '3'
services:
webapp1:
image: nginx
webapp2:
image: nginx
[email protected]:~/docker-compose$ docker-compose ps
Name Command State Ports
----------------------------------------------------------------------------------------
docker-compose_webapp1_1 /docker-entrypoint.sh ngin ... Up 0.0.0.0:8000->80/tcp
docker-compose_webapp2_1 /docker-entrypoint.sh ngin ... Up 0.0.0.0:8002->80/tcp
[email protected]:~/docker-compose$ docker-compose scale webapp1=4 webapp2=2
WARNING: The scale command is deprecated. Use the up command with the --scale flag instead.
Creating docker-compose_webapp1_2 ... done
Creating docker-compose_webapp1_3 ... done
Creating docker-compose_webapp1_4 ... done
Creating docker-compose_webapp2_2 ... done
[email protected]:~/docker-compose$
verify using the below command :
[email protected]:~/docker-compose$ docker-compose ps
Name Command State Ports
----------------------------------------------------------------------------------------
docker-compose_webapp1_1 /docker-entrypoint.sh ngin ... Up 80/tcp
docker-compose_webapp1_2 /docker-entrypoint.sh ngin ... Up 80/tcp
docker-compose_webapp1_3 /docker-entrypoint.sh ngin ... Up 80/tcp
docker-compose_webapp1_4 /docker-entrypoint.sh ngin ... Up 80/tcp
docker-compose_webapp2_1 /docker-entrypoint.sh ngin ... Up 80/tcp
docker-compose_webapp2_2 /docker-entrypoint.sh ngin ... Up 80/tcp
[email protected]:~/docker-compose$
As shown in the above output, a total of 6 containers are running and up. Users can configure the load balancer to distribute the load among containers.
Docker-compose top command displays the list of containers along with the number of running processes inside each container.
[email protected]:~/docker-compose$ docker-compose top
docker-compose_webapp1_1
UID PID PPID C STIME TTY TIME CMD
--------------------------------------------------------------------------------------------------
root 27249 27195 0 06:58 ? 00:00:00 nginx: master process nginx -g daemon off;
systemd+ 27421 27249 0 06:58 ? 00:00:00 nginx: worker process
systemd+ 27422 27249 0 06:58 ? 00:00:00 nginx: worker process
docker-compose_webapp1_2
UID PID PPID C STIME TTY TIME CMD
--------------------------------------------------------------------------------------------------
root 27741 27664 0 07:12 ? 00:00:00 nginx: master process nginx -g daemon off;
systemd+ 27869 27741 0 07:12 ? 00:00:00 nginx: worker process
systemd+ 27870 27741 0 07:12 ? 00:00:00 nginx: worker process