Instalando Docker em um WSL 2 com Ubuntu 22.04
Before start the installation process, make sure you meet the following prerequisites:
- A Windows 10 operating system with WSL 2 support.
- WSL 2 enabled.
- Ubuntu 22.04 installed on WSL 2.
Close the open terminal on Ubuntu.
Restart WSL via the Windows command line (Powershell).
wsl --shutdown
Access Ubuntu again. Check if Docker was installed correctly on the Ubuntu terminal:
docker --version
You should get a response similar to this:
Docker version 26.1.4, build 5650f9b
To start the Docker service run the following on the Ubuntu terminal:
sudo service docker start
To stop the Docker service run the following on the Ubuntu terminal:
sudo service docker stop
The performance of WSL 2 lies on running everything within Linux,
so avoid running your projects with Docker from the /mnt/c
path, as you will lose performance.
You can open a folder from Ubuntu with Windows Explorer by typing the command on your Ubuntu terminal:
explorer.exe .
The folder will be open using the Windows Explorer.
Remember to navigate to the desired folder on Ubuntu terminal beforehand.
On the Ubuntu terminal confirm that you can access the mounted drive and all its directories using the command below.
sudo ls /mnt/*
You have to see the list of folders and files currently present on your Windows C:/ folder.
If you can see the items just fine, then navigate until the destination folder on the Ubuntu terminal and use the following command.
cp -r /mnt/c/my-folder .
Where "my-folder" is the name of the folder on Windows that you want to copy and "." indicates the destination. Since that we are already on the destination folder we can use just "." , but you can inform the desetination path too.
cp -r /mnt/c/my-folder /home/my-user/my-folder
You can open a project with the IDE Visual Studio Code by typing the command on your Ubuntu terminal:
code .
Remember to navigate to the desired folder on Ubuntu terminal beforehand.
To free cache memory on Linux Ubuntu running on WSL you can use the following command on the Ubuntu terminal:
echo 1 | sudo tee /proc/sys/vm/drop_caches
To access your environment through Windows, I recommend using the Windows Terminal by Microsoft, also available on the Windows Store. This tool includes CLI tabs, a high degree of customization, and even native WSL support to open Linux-based windows.
If you want to see the official documentation, visit https://docs.docker.com/desktop/wsl/
Thank you!
You are welcome.
Very nice, thanks
Very nice, thanks
You are welcome.
Thank you!
Thank you!
You are welcome.
Thanks a lot!
Thanks for sharing this. It's really helpful.
Thanks a lot!
You are welcome.
Thanks for sharing this. It's really helpful.
You are welcome.
I want to know how to move Ubuntu and Docker to another drive, because I don't have space on my C drive.
I want to know how to move Ubuntu and Docker to another drive, because I don't have space on my C drive.
Hello. I never done this kind of drive migration before. However I found these two articles about the matter:
Maybe the information there can help you ?
It appears that WSL has some commands to help you on the migration process, but, again, I never done this before and I don`t know if it will work.
Good luck.
I want to know how to move Ubuntu and Docker to another drive, because I don't have space on my C drive.
Hello. I never done this kind of drive migration before. However I found these two articles about the matter:
- https://medium.com/@rahmanazhar/move-wsl-to-another-drive-ab8002152cf2
- https://blog.iany.me/2020/06/move-wsl-to-another-drive/
Maybe the information there can help you ?
It appears that WSL has some commands to help you on the migration process, but, again, I never done this before and I don`t know if it will work.
Good luck.
This is cool. Thanks.
Thank you
I actually need that since Vanilla OS requirement is pretty high on disk space. I learnt of export import from TroubleChute video. I will have to check the actual .vhdx on the environment path tho, by using diskpart.
Oh yeah, I first found this from the sparse feature issue in wsl, that lead me to diskpart feature, and eventually export import feature.
I was researching backup option in linux, but since wsl is a vm, turns out export import is more than enough instead of foxclone or timeshift.
For reducing disk space, backup, and moving the wsl .vhdx VM file, links:
https://superuser.com/questions/1606213/how-do-i-get-back-unused-disk-space-from-ubuntu-on-wsl2
Thanks for the notif tho, now I will check my .vhdx to use other distro and move it to other disk. I do hope the imported .vhdx doesn't resides in windowsapp/Ubuntu directory anymore which is on C:
Thank you
You are welcome.
I actually need that since Vanilla OS requirement is pretty high on disk space. I learnt of export import from TroubleChute video. I will have to check the actual .vhdx on the environment path tho, by using diskpart.
Oh yeah, I first found this from the sparse feature issue in wsl, that lead me to diskpart feature, and eventually export import feature.
I was researching backup option in linux, but since wsl is a vm, turns out export import is more than enough instead of foxclone or timeshift.
For reducing disk space, backup, and moving the wsl .vhdx VM file, links: https://superuser.com/questions/1606213/how-do-i-get-back-unused-disk-space-from-ubuntu-on-wsl2
Thanks for the notif tho, now I will check my .vhdx to use other distro and move it to other disk. I do hope the imported .vhdx doesn't resides in windowsapp/Ubuntu directory anymore which is on C:
Thanks for sharing.
Export, import is still my way to go.
There's another option by the same YTber, using junction, though I would say this is for advance user only since hardlink symbolic link and junction have their differences in use case.
There's a good chart of this in ss64 website.
So I still prefer --export --vhdx and other options
Then --import.
The diskpart program made by one of the user in that github issue is nice too, since it pings the .vhdx file location
This is the link to the backup solution (if some users can't find it because of YT search being dependent on keyword), I just found it today there's a junction option if you search 'backup' or 'move data':
https://youtu.be/-R4VcMCkc6k
(It's fast in my m2 SSD, it would probably be slower in HDD)
Edit:
Spellings, wordings.
Edit 2:
Forgot to tag the person asking about moving the wsl virtual disk from one partition to another.
Thank you! Great content!
Thank you! Great content!
You are welcome.
You rock !! thank you ;) ...
Thank You!
thanks
You rock !! thank you ;) ...
You are welcome.
Thank You!
You are welcome.
thanks
You are welcome.
nice one sir!
Because you shouldn't seriously entertain using any mounted windows drive:
I'd set the /etc/wsl.conf
to
[automount]
enabled = false
[interop]
enabled = false
appendWindowsPath = false
[boot]
command = service docker start
Working solely in wsl is the ideal workflow.
But to move or copy paste files, usually autompint automount* is easier than manual setup.
Move or copy are fine.
Just don't do something like wet wget* across system.
If you got unlimited internet data with FUP. There are syncthing and its forks for copy paste or mirrored files/notes.
I'll share my personal .conf and wsl.config later when I get to open my pc at home.
It depends on the user needs.
One could also min max the values in umask etc. For beginner I mainly just use default.
I forgot to synced my wsl configs using syncthing so it's only in my pc, rn.
Also, since I haven't got the time to fully deploy docker, my configs are mainly for wsl and distro.
There's something like loop address for docker but I only find it in issue not yet in practice. ( I was researching each confs that have to do with docker.)
I was doing wsl DE GUI to set up waydroid, but the kernel also stop me from doing it.
There's also a drop cache problem in wsl if it's set to auto.
Links:
https://gist.github.com/gorshkov-leonid/b55072d6876acecf43dabaf7f1e72cf0
https://gist.github.com/martinsam16/4492957e3bbea34046f2c8b49c3e5ac0
(Anyone are free to chime in for docker wsl configs optimization, I only know some optimization for wsl case. Docker wsl configs are in my waitlist but not priority;
since I only intend to taste Linux dev env in wsl, but was intrigued by andro emu in linux as an OS alt to proprietary windows andro emu)
Edit misspellings
edit 2:
wsl.conf inside wsl (I can't check my latest one, I forgot I backed up my wsl instance [wsl --export] and set up andro emu on windows again, so all virt are disabled, to make an emu that use intel bridge and virtual box to use the virt feature from bios, virtualization enabled in taskmgr, directly)
# Automatically mount Windows drive when the distribution is launched
[automount]
# Set to true will automount fixed drives (C:/ or D:/) with DrvFs under the root directory set above. Set to false means drives won't be mounted automatically, but need to be mounted manually or with fstab.
enabled = true
# Sets the directory where fixed drives will be automatically mounted. This example changes the mount location, so your C-drive would be /c, rather than the default /mnt/c.
# root = /
# DrvFs-specific options can be specified.
# pinned gist. To avoid this error https://askubuntu.com/questions/1115564/wsl-ubuntu-distro-how-to-solve-operation-not-permitted-on-cloning-repository
options = "metadata"
# ,uid=1003,gid=1003,umask=077,fmask=11,case=off"
# Sets the `/etc/fstab` file to be processed when a WSL distribution is launched.
# mountFsTab = true
# Network host settings that enable the DNS server used by WSL 2. This example changes the hostname, sets generateHosts to false, preventing WSL from the default behavior of auto-generating /etc/hosts, and sets generateResolvConf to false, preventing WSL from auto-generating /etc/resolv.conf, so that you can create your own (ie. nameserver 1.1.1.1).
# [network]
# hostname = DemoHost
# generateHosts = false
# generateResolvConf = false
# Set whether WSL supports interop processes like launching Windows apps and adding path variables. Setting these to false will block the launch of Windows processes and block adding $PATH environment variables.
# gist pinned. To avoid collisions. Any necessary paths can be set manually
[interop]
enabled = true
appendWindowsPath = false
# Set the user when launching a distribution with WSL.
# [user]
# default = DemoUser
# Set a command to run when a new WSL instance launches. This example starts the Docker container service.
[boot]
systemd = true
# command = service docker start
wsl.config
# Settings apply across all Linux distros running on WSL 2
[wsl2]
# Limits VM memory to use no more than 4 GB, this can be set as whole numbers using GB or MB
memory=3GB
# Sets the VM to use two virtual processors (logical processor, core x threads iirc)
processors=5
# Specify a custom Linux kernel to use with your installed distros. The default kernel used can be found at https://github.com/microsoft/WSL2-Linux-Kernel
# kernel=C:\\temp\\myCustomKernel
# Sets additional kernel parameters, in this case enabling older Linux base images such as Centos 6
# kernelCommandLine = vsyscall=emulate
# Sets amount of swap storage space to 8GB, default is 25% of available RAM
swap=8GB
# Sets swapfile path location, default is %USERPROFILE%\AppData\Local\Temp\swap.vhdx
# swapfile=C:\\temp\\wsl-swap.vhdx
# Disable page reporting so WSL retains all allocated memory claimed from Windows and releases none back when free
pageReporting=true
idleThreshold=1
guiApplications=true
# Turn on default connection to bind WSL 2 localhost to Windows localhost. Setting is ignored when networkingMode=mirrored
localhostforwarding=true
# Disables nested virtualization
# nestedVirtualization=false
# Turns on output console showing contents of dmesg when opening a WSL 2 distro for debugging
# debugConsole=true
# networkingMode = mirrored # https://github.com/microsoft/WSL/issues/10494
# Enable experimental features
[experimental]
sparseVhd=false
autoMemoryReclaim=dropcache
# hostAddressLoopback = true # https://github.com/microsoft/WSL/issues/10494
nestedVirtualization = true
# 2nd order after normal documentation. the above are from microsoft wsl example of wsl dot config
# pinned
# idleThreshold=1
# pinned no documented conclusive solution yet
# for docker instance, eg
# vmIdleTimeout=-1 (error, not working for now. this is supposed to disable timeout or make it infinite)
vmIdleTimeout = 604800000
Yeah, old wsl.conf
Sadly my wsl.conf is inside a wsl.vhdx backup.
Interop better be off indeed. Not sure about vscode integration but, I haven't reached that part yet.
I think having a text editor or DE inside wsl is better, I don't know yet how to access wsl things from Windows vscode integration.
There's a devops oriented distro, but I'm not sure if Linux ISOs need just to be tar'd so that it could be imported into wsl. Or it's more complex than that.
Edit:
I got the name now: bluefin
https://news.ycombinator.com/item?id=38992292
Thank you!