5

I would like to run entire docker container in memory without mapping volumes to host's hard drive.

TMPFS described here helps to mount volumes as "memory volumes", but I'm looking a way how to start entire container mapped to memory.

--volume-driver probably what I have to use, but I can't find a documented list of supported drivers (not overlay2).

So, I've tried:

docker run -td --name my-container --volume-driver tmpfs container-image
docker run -td --name my-container --volume-driver memfs container-image

But in both cases, with docker inspect my-container I observed that:

    "GraphDriver": {
        "Data": {
            "LowerDir": "/var/lib/docker/overlay2/d1d112972c6b531976dd33e27edf213fc578856c3ee96b99c9afe53ad3f71a5e- ... /diff",
            "MergedDir": "/var/lib/docker/overlay2/d1d112972c6b531976dd33e27edf213fc578856c3ee96b99c9afe53ad3f71a5e/merged",
            "UpperDir": "/var/lib/docker/overlay2/d1d112972c6b531976dd33e27edf213fc578856c3ee96b99c9afe53ad3f71a5e/diff",
            "WorkDir": "/var/lib/docker/overlay2/d1d112972c6b531976dd33e27edf213fc578856c3ee96b99c9afe53ad3f71a5e/work"
        },
        "Name": "overlay2"
    }

docker stats also points me that both cases are using default mapping strategy.

Victor Perov
  • 1,697
  • 18
  • 37
  • I've found the documentation of supported storage drivers https://docs.docker.com/v17.09/engine/userguide/storagedriver/, and seems it is not what I have look for. – Victor Perov Apr 08 '19 at 13:48

1 Answers1

2

There is an issue that as been closed to do just that. Here is a link to the comment https://github.com/moby/moby/issues/10490#issuecomment-311892718.

In essence, it configures docker to save images in RAM. It will do what you want, but you'll lose your images if you shut down.

Now, I am not sure why you would want that, but I will extrapolate on what I think your need might be:

  • You want no trace after the run of your container: Then, add the --rm flag that will remove the files that will always be created. This keeps your run clean, but possibly not completely secure.

  • You do not want any of the data you will have to write to be persisted on disk for security reasons : Then you will have to mount a tmpfs (https://docs.docker.com/engine/reference/run/#tmpfs-mount-tmpfs-filesystems) somewhere in your container and only write there. Please keep in mind that if swap is used, the content will be written to disk, and potentially recoverable.

  • You want fast read of the data already present in the container: Then I think your best bet is that when your container start, to copy the data you need fast access to in a tmpfs mounted in the container.

I hope I caught your use case and helped, if not, please say so :)

Romain Prévost
  • 513
  • 2
  • 12
  • Thanks for your reply! The my main idea to have entire container in memory related to make my tests with database container more stable and quicker. I would like to have all of my tables like memory tables without changing it in table engines and just switch "ground" layer of my database container. – Victor Perov Apr 09 '19 at 11:26
  • So, described ideas are really good, and definitely should be applied to different scenarios, you described. But in my case I'm looking to running entire "service" as service in memory only. – Victor Perov Apr 09 '19 at 11:27
  • @VictorPerov did you finda solution to this? I have the same use case for our tests. – digao_mb Dec 17 '20 at 20:33
  • @digao_mb, maybe open a new question describing your test cases, you'll get more informed answers. – Romain Prévost Dec 24 '20 at 09:21