3

Is it possible to have performance issues in Docker?

Because I know vm's and you have to specify how much RAM you want to use etc.

But I don't know that in docker. It's just running. Will it automatically use the RAM what it needs or how is this working?

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250

2 Answers2

3

Will it automatically use the RAM what it needs or how is this working?

No by default, it will use the minimum memory needed, up to a limit.

You can use docker stats to see it against a running container:

$ docker stats redis1 redis2
CONTAINER           CPU %               MEM USAGE / LIMIT     MEM %               NET I/O             BLOCK I/O
redis1              0.07%               796 KB / 64 MB        1.21%               788 B / 648 B       3.568 MB / 512 KB
redis2              0.07%               2.746 MB / 64 MB      4.29%               1.266 KB / 648 B    12.4 MB / 0 B

When you use docker run, you can specify those limits with Runtime constraints on resources.
That includes RAM:

-m, --memory=""     

Memory limit (format: <number>[<unit>], where unit = b, k, m or g)

Under normal circumstances, containers can use as much of the memory as needed and are constrained only by the hard limits set with the -m/--memory option.
When memory reservation is set, Docker detects memory contention or low memory and forces containers to restrict their consumption to a reservation limit.

By default, kernel kills processes in a container if an out-of-memory (OOM) error occurs.
To change this behaviour, use the --oom-kill-disable option. Only disable the OOM killer on containers where you have also set the -m/--memory option.

Note: the upcoming (1.10) docker update command might include dynamic memory changes. See docker update.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
1

By default, docker containers are not limited in the amount of resources they can consume from the host. Containers are limited in what permissions / capabilities they have (that's the "container" part).

You should always set constraints on a container, for example, the maximum amount of memory a container is allowed to use, the amount of swap space, and the amount of CPU. Not setting such limits can potentially lead to the host running out of memory, and the kernel killing off random processes (OOM kill), to free up memory. "Random" in that case, can also mean that the kernel kills your ssh server, or the docker daemon itself.

Read more on constraining resources on a container in Runtime constraints on resources in the manual.

thaJeztah
  • 27,738
  • 9
  • 73
  • 92