Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why docker container is consuming lot of memory?

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)

docker stats

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.)

like image 901
C.P. Avatar asked Oct 08 '16 14:10

C.P.


People also ask

How do I make docker use less 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.

Does docker take a lot of memory?

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.

How much memory does a docker container take?

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.

Why is docker using so much space?

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.


1 Answers

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:

  • Number of CPUs
  • Memory
  • Swap
  • Disk Image Size

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.

like image 132
dave4jr Avatar answered Sep 19 '22 21:09

dave4jr