Manually Assign Memory Size To Docker Container In Linux

We can manually assign and allocate memory size or usage to a docker container usage. you can find the statistics of running docker container using the single command docker stats container_name –no-stream.

Manually Assign Memory Size:

Once we have setup Memory allocation to a container. we can also monitor running containers using the monitoring too like Prometheus and Grafana

Check Out: How To Create bucket In S3 Storage On AWS Cloud

By Default, Docker assigns the total memory of VM to the container if  there is one
running otherwise it distributes RAM automatically if you have more container is
running on the same VM. 

You can manually assign memory size to the container according to your application
need. I will show you how to do that.

Check Out: Manually pull Version

I have created a container of PHP without specifying the RAM manually

We will Download PHP Image

docker images

Manually Assign Memory Size

Create a Container of PHP

docker run it --name phpmem cd45c80ef616 /bin/bash

allocate memory docker container

Check Out: Install Docker

As you can see by default Docker has assigned memory to phpmem container which
is 0.05%. That's not total memory assign as I have run other containers on this VM
too.
docker stats phpmem –no-stream

Assign Memory to phpmen container manually

docker run -it –name phpmem -m 200m cd45c80ef616 /bin/bash

Check Out: How To Install Ubuntu Server 18.04 On Vmware Workstation

I have to assign 200MB to phpmem container here and now you have to check the memory of the container.

YouTube Link: Set the memory to docker container

You’re done  container  assign memory docker allocate    usage

Share on:

I'm the founder of Curious Viral. I hope this blog will provide you complete information about Linux Technology & I would like to share my technical knowledge with you which I have learned during this period.

Other Posts You May Like...

Leave a comment