I have a workload where I want to use a container to write data to a tmpfs volume mounted from the host with -v. I would expect that data written to the volume would not count towards Docker’s memory limit for the container doing the write. However, data written to the host-mounted volume seems to count towards the container’s memory limit. Is this correct behavior? Is there any way to have a container write more data than its memory limit to the memory of the host machine?
Reproduction steps from a freshly-provisioned EC2 machine running amazon linux:
sudo yum install -y docker # Mount a 5GB tmpfs sudo mkdir /mnt/tmpfs && sudo mount -t tmpfs -o size=5G tmpfs /mnt/tmpfs # Get some data. This file is 3GB wget https://datasets.elasticmapreduce.s3.amazonaws.com/ngrams/books/20090715/eng-us-all/1gram/data --no-check-certificate sudo service docker start sudo docker run --rm --memory=2G -it -v /mnt/tmpfs:/mnt/tmpfs -v ~/data:/data ubuntu /bin/bash # Inside the container now cp /data /mnt/tmpfs # The cp command gets killed
If we don’t set the 2G memory limit, the copy will finish successfully.