Runtime constraints on resources
It may be useful to restrict the Docker container usage on resources when running. Docker gives you a lot of possibilities to set constraints on the memory, CPU usage or disk access usage. Let's begin with setting the memory constraints.
Memory
It's worth knowing, that by default, that is if you use the default settings without any constraints, the running container can use all of the host memory. To change this behavior we can use the --memory
(or -m
for short) switch for the docker run
command. It takes a usual suffixes k,m, or g for kilobytes, megabytes and gigabytes respectively.
The syntax of the docker run
command with memory constraints set will be as follows:
docker run -it -m 512m ubuntu
The preceding command ...
Get Developing with Docker now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.