Running last version of docker on top of ubuntu 13.04
root@docker:~# docker version
Client version: 0.6.6
Go version (client): go1.2rc3
Git commit (client): 6d42040
Server version: 0.6.6
Git commit (server): 6d42040
Go version (server): go1.2rc3
Last stable version: 0.6.6
But when I start the container
root@docker:~# docker run -m=1524288 -i -t ubuntu /bin/bash
root@7b09f638871a:/# free -m
total used free shared buffers cached
Mem: 1992 608 1383 0 30 341
-/+ buffers/cache: 237 1755
Swap: 2047 0 2047
I don't see any limiting from any kind, and my kernel has cgroups memory limit enabled:
kernel /boot/vmlinuz-3.8.0-33-generic ro console=tty0 root=/dev/xvda1 cgroup_enable=memory swapaccount=1
What obvious thing am I missing here ?
free
won't show it as this is enforced via cgroups. Instead on the host (outside the container) you can check using/sysfs
and the cgroup memoryTo see it run out of memory you can run something that will use more memory than you allocate - eg:
In
dmesg
you should see the container and process killed:If you are using a newer version of docker, then the place to look for that info is
/sys/fs/cgroup/memory/docker/<container_id>/memory.limit_in_bytes
:Linking to this nice post on stressing container memory usage. Here's the summary, modified a bit to work for docker instead of generic LXC:
Launch container with a memory limit:
Create a file
foo.c
inside the container with the followingCompile the file
Open a new terminal to monitor the container memory usage:
Start the memory consumption in the container
Now watch your container max out. Note: When you're out of memory malloc's start to fail, but otherwise the container is left alone. Normally the software inside the container will crash due to the failing mallocs, but software that is resilient will continue to operate
Final Note: Docker's -m flag does not count swap and ram separately. If you use
-m 512M
then some of that 512 will be swap, not RAM. If you want only RAM you will need to use LXC options directly (which means you will need to run docker with the LXC execution driver instead of libcontainer)There is a notable difference between using swap as part of the total and not - with swap the foo program above reaching ~450M quickly and then slowly consumes the remainder, whereas with only RAM it immediately jumps to 511M for me. With swap the container's memory consumption is marked at ~60M as soon as I enter the container - this is basically the swap being counted as "usage". Without swap my memory usage is <10M when I enter the container