How to use Docker Image for Vertical Scaling In Docker
Now we can start the container from the docker image specifying the amount of resources it should use.
docker run -it -p 8000:5000 –cpus 1 –memory 1g flaskapi
The above command will start the docker container from the flask API image, we have specified the number of CPUs it can use and also the amount of memory it can use. We have started the container in the detached mode specified using the -d flag and mapped port 8000 on the local host to port 5000 inside a container where the flask API is listening.
Now considering that the number of requests coming to the API increases, we can just start another container from the image with more ram and CPU, and as soon it gets up we can stop the previous container.
docker run -it -p 8000:5000 –cpus 2–memory 2g flaskapi
How to Use Docker Images For Scaling Applications?
Docker image is a lightweight piece of software that includes everything that your application needs to run, it includes code, software packages, and libraries. Docker images are built using a Docker file which includes the instruction for creating the image. The Docker image is built on top of a base image which is specified on top of the Dockerfile.
Docker images are typically stored in the docker registry such as the DockerHub, or Artifactory. Dockerfile is a source code for Docker images.