简体   繁体   中英

Can I use docker tmpfs in WSL2 for running docker containers on RAM?

Is docker tmpfs working on wsl2.
If I run this in WSL2:

docker run -it --rm -e POSTGRES_PASSWORD=secret --tmpfs /var/lib/postgresql/data postgres:13-alpine sh

The whole container will run in the RAM?

[EDIT] As @Nik found, tmpfs in WSL is currently mapped to filesystem. At command line level it works as it is mapped in RAM, but it is actually mapped to filesystem. So, take care of this caveat until it is implemented as one would assume.

According to your first question: "Is docker tmpfs working on wsl2?" it seems the answer is yes. In fact, try to run a container like that:

$ docker run -it --name tmptest --mount type=tmpfs,destination=/mytmp busybox 

If you then inspect the container, you can see that /mytmp is mounted correctly as a tmpfs :

"Mounts": [
    {
        "Type": "tmpfs",
        "Source": "",
        "Destination": "/mytmp",
        "Mode": "",
        "RW": true,
        "Propagation": ""
    }
]

Some notes about your second question "The whole container will run in the RAM?" :

  1. It's just the content of the folder /var/lib/postgresql/data that is stored in RAM, not the "whole container" whatever you think that means.

  2. It seems to me you're not running the db but a shell instead. So, unless you start the db from the shell I guess you would have no particular advantages in having /var/lib/postgresql/data in RAM.

  3. Technically speaking any program has to be loaded in RAM to work, or at least the portion that is currently executed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM