I am new to docker. I have a nodejs(sails.js) application. I have deployed it using docker. There is only one docker container running on my Ubuntu machine.
When I tried to monitor the memory usage by my docker container using "docker stats" command, below is the stats I get (as shown in image)
My question is, why this single docker container is eating lot of memory ~207MiB? In future if I want to increase the number of containers running per host, will it consume memory in this multiples? It doesn't seem to be feasible solution if I want to run 100 container of same app on my machine. Is there any way to optimize memory consumption by docker containers?
(When I run the same application without docker (sails lift / node app.js) it only consumes 80MB of memory.)
To limit the maximum amount of memory usage for a container, add the --memory option to the docker run command. Alternatively, you can use the shortcut -m . Within the command, specify how much memory you want to dedicate to that specific container.
Docker does not apply memory limitations to containers by default. The Host's Kernel Scheduler determines the capacity provided to the Docker memory. This means that in theory, it is possible for a Docker container to consume the entire host's memory.
The minimum allowed value is 4m . Because kernel memory cannot be swapped out, a container which is starved of kernel memory may block host machine resources, which can have side effects on the host machine and on other containers. See --kernel-memory details.
Docker takes a conservative approach to cleaning up unused objects (often referred to as “garbage collection”), such as images, containers, volumes, and networks: these objects are generally not removed unless you explicitly ask Docker to do so. This can cause Docker to use extra disk space.
I know this question is old, but I thought it was worth adding that if you are using Docker For Mac, you can navigate to Docker > Preferences > Resources > Advanced
, and on that page are several options to control resource settings such as:
and other various settings. I've noticed that if I signify 2GB of memory, as long as the Docker desktop is running, it will use the entire 2GB of memory.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With