Using docker with hypervisor instead of wsl2 - docker

Before I hear about wsl, I was using virtualbox and some other software to use linux. But wsl was amazing. Instead of allocating mamory wsl uses dynamic allocation that was really useful. When I heard about wsl2 in docker I was really happy. But nothing went as expected. A process named vmmem starts with wsl2 backend and uses almost 2gbs of ram. Even if I use the hyper-v backed I would not allocate that much memory. Even with wsl2 ubuntu or wsl2 kali the same process starts but does not allocate that memory. I searched on youtube, Quora, Google and everything I could not get any solutions.
I wanted to switch back to hyper-v backend or wanted to get rid of the vmmem process, So please help me
Thanks to everyone who read this kindly and special thanks to the one who is going to solve my problem
I can give you any additional information if you want

To answer your question, there is a checkbox in the Docker settings (right click Docker icon > Settings > General) labelled "Use the WSL 2 based engine" which will do what you are looking for.
However, if you want to give WSL another go, you can limit the amount of memory that WSL can allocate.
If you create a file in your %userprofile%, called .wslconfig and give it the contents:
[wsl2]
memory=1GB
However, there is an ongoing issue with WSL2 and Docker that appears to indicate a memory leak. Limiting the memory in this way may cause undesirable side effects.

Related

How to limit memory usage when I run Memgraph Platform within Docker?

I've been running Memgraph for a few days now and everything is working as expected. This is the first time that I'm using Docker.
I've noticed that when I shut down the Memgraph Platform my RAM is still used. I need to restart my computer to free up my RAM. Is there some switch that I can use to limit the memory that Memgraph Platform uses? Is there some way to release the memory after I shut it down?
If it is important, my OS is Windows 10 Professional and I have a 6 years old laptop with 8GB of RAM.
The issue you are experiencing is not related to Memgraph, but Docker or to WSL2 to be more precise. You say that you use Windows 10 so I presume your Docker is configured to use WSL2.
You didn't write which exact build of Windows 10 you are using, but depending on it WSL can use up to 80% of your RAM if you don't limit it.
When you run the Docker image you will see a process called vmmem. When you shutdown running Docker image this process will still occupy your RAM. Restarting your computer frees up the RAM, which is what you are experiencing.
The solution is not to change the configuration of your Memgraph, but to configure Docker. You need to limit the amount of memory that WSL2 can use. But be careful; this is a change that will affect all of your WSL2 instances, not just the Docker ones.
The exact steps that you need to do are:
Shutdown all of the WSL instances with wsl --shutdown
Edit the .wslconfig file (it is located in your user profile folder)
Add the following lines to it:
[wsl2]
memory=3GB
This will limit the RAM usage of WSL to 3GB. I hope that this will help you.

docker desktop wsl 2 backend has stopped unexpectedly

I am facing issue with Docker desktop. it is getting crashed in 15-20 min.
Docker Desktop 4.3.2
Docker 20.10.11
Windows 10 PRO
reference link: https://github.com/docker/for-win/issues/12477
I met that problem too, but that's when I start a relatively big image/container, and don't see many useful solutions on the community.
One tutorial that I follow is, add some config documents to limit the RAM use of the WSL-2, and restart my PC, it seems to work.
User Win+R, then enter '%UserProfile%' to enter the user dictionary in Windows, create a file: '.wslconfig', and then edit the file as follows:
[wsl2]
memory=8GB
swap=0
localhostForwarding=true
The 'memory' should be edited by the condition of our laptops, I used 4GB in my one. Then restart the PC.
I'm new to Docker, don't know whether it's the right solution, but it seems work in my laptop:D Hope that can help someone meet the same problem.

Incrementing GB of Ram for Docker Container in Windows

I am following this tutorial https://docs.docker.com/docker-for-windows/#docker-settings-dialog to install docker in windows. I am stuck on the Settings section under Resources tab. My view of resources does not show how it is showing on that link. Is there a way to increase my Ram so I can have ELK to run. I installed the Docker Desktop application with the Hyper-V.
This is what I see in my settings.
What I should be seeing, but am not.
Though you mention using Hyper-V, because of your screenshot (notably the WSL Integration tab), I suspect you may be running Docker Desktop in WSL2 mode, instead of HyperV mode. (WSL2 to my understanding is the newer, faster option in many cases).
With that assumption, to alter the RAM in your WSL 2 VM, you have to create a C:\Users\username\.wslconfig file with the VM settings. The details are described on this page which is actually linked to by the page you mentioned.
This is an example of a .wslconfig file:
[wsl2]
memory=9GB # Limits VM memory
Note that this applies to all WSL2 VMs (I guess they are called distros?), which I'm not sure is exactly the right answer, since Docker seems to produce 2 distros by itself, plus whatever other distros you have (see wsl --list). Do you want to increase the RAM for all distros?
However, to quote this page:
WSL 2's memory usage grows and shrinks as you use it. When a process frees memory this is automatically returned to Windows.
This sounds to me like the .wslconfig memory setting is a max size, which is only allocated when needed, so I assume setting it for all WSL distros won't cause all of them to balloon up to 9GB immediately upon distro startup unless those distros try to use all that memory.
They go on to say:
However, as of right now WSL 2 does not yet release cached pages in memory back to Windows until the WSL instance is shut down. If you have long running WSL sessions, or access a very large amount of files, this cache can take up memory on Windows. We are tracking the work to improve this experience on the WSL Github repository issue 4166
I have experienced this ballooning memory issue on large ML jobs, so just something to be aware of.
So, the .wslconfig change has seemed to work for me. Another option that has helped me is increasing the swap size via .wslconfig, since my machine has limited memory.

Docker could not start because I do not have enough memory. How to solve it?

I got into a HTML/CSS/JavaScript course and I need Docker Desktop installed an functionally on my laptop. The problem is that I can not start it because I do not have enough memory, the error is appearing every time when I try to start it. I have tried to solve it by lowering the settings of the Docker Engine, free up some memory with RAMMap and turn Windows to performance mode, but unfortunately the error is still here.
The laptop that I work on has only 2 GB of RAM. Is there a solution to start Docker?

Making use of docker for development: a use case

my question is little vague but I tried looking for the answer here and there but could not understand if I can leverage docker for my work. My requirements
I usually try different versions of java, python and other software like different versions of eclipse, Linux package and other tools. This at the end make my Ubuntu installation a complete mess and some time completely broken. Then I started using Vm it solve most of the problem but make my pc very slow for frequent switching.
So my question can I achieve my work using docker without affecting my os? Can I run gui application, install different package without affecting underlying OS.
Switch actively between different docker container and underlying os.
Clean/remove unused/broken install of docker instance (containers?) etc. Any pointer to similar use case or how to would be helpful.
Thanks.
Ps- if it doesn't fit for SO then please move it to where it is best fitted. Sorry for non programming question.
Can it be done?
yes, there are examples of docker images that run graphical application, but running those containers might be a bit tricky. See for instance Can you run GUI apps in a docker container?
Is Docker the right tool for your problem ?
Maybe a package manager such as Nix would be better suited, as graphical software installed with it won't have any issue. With Nix you can install side-by-side many versions of a single software without interference.

Resources