features icon indicating copy to clipboard operation
features copied to clipboard

`docker-in-docker` feature wastes RAM by mounting `/tmp` to tmpfs

Open DanielHabenicht opened this issue 2 years ago • 5 comments

It seems like adding the feature like so:

{
	"name": "Python 3",
	"image": "mcr.microsoft.com/devcontainers/python:0-3.11",
	// Features to add to the dev container. More info: https://containers.dev/features.
	"features": {
    		"ghcr.io/devcontainers/features/docker-in-docker:2": {
	}
}

Mounts /tmp to tmpfs on default: https://github.com/devcontainers/features/blob/3cc059ea8abf3a909468fafabca481f82b6f8924/src/docker-in-docker/install.sh#L353-L356

Which results in some unexpected behaviours:

  1. The /tmp directory is now limited by the amount of RAM that is available, which results in Out of space Exception for programs using a lot of tmp space (or users with limited amount of RAM).
  2. The RAM of the host system is wasted for tmp files.

Workaround:

Mounting your own volume to /tmp: "runArgs": ["--mount", "type=volume,target=/tmp/"],

Related

Here is my way of suffering: https://stackoverflow.com/questions/75630189/why-and-where-is-the-tmp-directory-size-limited-in-vscode-devcontainers ;)

DanielHabenicht avatar Mar 03 '23 18:03 DanielHabenicht

Hi 👋

Thanks for letting us know, it's interesting that users are facing memory issues due to docker-n-docker Feature. It's great that you were able to find a workaround to unblock this.

I believe the mounting to tmpfs is for performance boosts (like faster cache). Said that are you suggesting to remove the mounting to tmps in the Feature or are you looking forward to share your insights so that the community can unblock themselves (with your suggested workaround)?

samruddhikhandale avatar Mar 03 '23 18:03 samruddhikhandale

Hi,

I dont know anything about the reasons why its there. But assuming it is there for a reason (performance) I would suggest to move it to a folder that is not used by most other applications (if that is possible).

E.g. /tmp/dnd-cache

DanielHabenicht avatar Mar 03 '23 18:03 DanielHabenicht

This caused a similar issue for me. I use /tmp in the container for copying files that don't really belong in the workspace (one-off scripts usually). When I copy a script to /tmp in the Dockerfile and then run it in ~~postCreateCommand~~ postAttachCommand, it fails when docker-in-docker is enabled, but works if it's not enabled. I'll be able to work around it now but it was a head scratcher because suddenly the file isn't there. There error is just "file not found".

jifalops avatar Jun 02 '23 01:06 jifalops

Does anyone know where to put this "runArgs": ["--mount", "type=volume,target=/tmp/"], workaround from @DanielHabenicht ?

wolfch-elsevier avatar May 06 '24 00:05 wolfch-elsevier

I was able to do another workaround to avoid the tmpfs mount for /tmp by doing a bind mount of the hosts' /tmp via this config addition to .devcontainer/devcontainer.json:

  "mounts": [
    "type=bind,src=/tmp,dst=/tmp"
  ],

The result looks like:

Filesystem          Size  Used Avail Use% Mounted on
overlay              59G   15G   41G  27% /
tmpfs                64M     0   64M   0% /dev
shm                  64M     0   64M   0% /dev/shm
/host_mark/private  466G  445G   21G  96% /tmp
/dev/vda1            59G   15G   41G  27% /vscode
/host_mark/Users    466G  445G   21G  96% /workspaces/myrepo

wolfch-elsevier avatar May 06 '24 01:05 wolfch-elsevier