WSL 2 on Windows - LINUX based development environment and Docker
Windows operating system provides "Windows Subsystem for Linux" which can be utilized to develop using Linux operating system and have Linux based tools. Windows operating system is providing a great interoperability so that it is very easy to operate between Linux distribution and base operating system. I still remember the old days where we had to do so many things to have Linux OS with the base operating system. Popular choices were to have dedicated partitions to have different Operating systems or have Virtual Machine to host any OS of your choice. For both the cases, the development experience was not that great.
Modern development is based on Containerization technologies and for Windows operating system, Docker Desktop is a popular choice to create docker environment in Windows operating system. Docker Desktop was using Hyper-v based virtualization technology and Linux OS to provide required environment. Later it started supporting WSL to provide containerization capabilities.
Recent licensing agreement says Docker Desktop is not free for enterprises and you need license to use it. Docker Desktop is a great tool but it has license cost associated with it. New tools are coming like Rancher Desktop which shows great potential. You may explore these tools if you are comfortable using GUI based tools. If you are comfortable using command and CLIs then you can setup you own environment using WSL2.
I have recently configured my development setup using WSL2 on Windows 11.
I have noted all the tips and tricks to resolve the issues which I encountered during this journey.
Step 1 : Setting up WSL 2 in WINDOWS 10/11
Click on "Turn Windows Features on or off" . Enable "Windows Sub System for Linux" and "Virtual Machine Platform"
Open power shell
How to see available distributions?
> wsl -l -v
> wsl --install -d <distribution name>
example : wsl --install -d Ubuntu-20.04
Note down username and password.
To unregister distribution :
Step2 : Mounts - accessing windows file in Linux and vice versa
Seeing Linux files in WINDOWS
\\wsl$
This will show all the distributions and you can enter into specific distributions
\\wsl.localhost\Ubuntu-20.04
Accessing Windows file system in WLS distribution
use /mnt to navigate any to drive.or /mnt/d/<sub-folder>
use ls command to see the files
testuser@vvdsfsf04:/mnt/c$ sudo ls
Step 3: Using Visual Studio Code to modify Linux projects
testuser@vvdsfsf04:~$ code .
It should open Visual Studio Code with Linux terminal so that you can execute any Linux command from here. You can install "Remote WSL" extension upfront.
You can also connect WSL distributions form visual studio
Open Visual Studio Code
Press Ctrl + Shift + P and the search "new WSL window with Distribution". You should be able to select installed distributions.
Step 4: Windows terminal
Step 6 : Installing Docker
> sudo systemctl enable docker
> sudo systemctl enable docker.service
> sudo systemctl enable containerd.service
System has not been booted with systemd as init system (PID 1). Can't operate. Failed to connect to bus: Host is down
You can use instead
> sudo service docker start
> sudo --status-all
Avoid starting every time, You can follow the below steps to start at start-up --
Step 1:
> sudo visudo<username> ALL=(ALL) NOPASSWD: /usr/bin/dockerd
echo '# Start Docker daemon automatically when logging in if not running.' >> ~/.bashrcecho 'RUNNING=`ps aux | grep dockerd | grep -v grep`' >> ~/.bashrcecho 'if [ -z "$RUNNING" ]; then' >> ~/.bashrcecho ' sudo dockerd > /dev/null 2>&1 &' >> ~/.bashrcecho ' disown' >> ~/.bashrcecho 'fi' >> ~/.bashrc
>> sudo usermod -a -G docker <<user>>
Step 7: Accessing Linux applications from WINDOWS
https://docs.microsoft.com/en-us/windows/wsl/networking
ip addr | grep eth0
From Windows - https://172.20.80.183/
Step 8: Accessing Windows applications from Linux
cat /etc/resolv.conf
From Linux -- curl http://172.20.80.1:500
Testing Docker and docker compose -
Follow this link - Opendistro Installation
/etc/sysctl.conf -- modify in this file
> grep vm.max_map_count /etc/sysctl.conf
> sudo nano /etc/sysctl.conf
verify this
> cat /etc/sysctl.d/99-sysctl.conf
execute this command
sudo sysctl -w vm.max_map_count=262144
Use docker compose command to have elastic search and use Step 7 to access Kibana.
Comments
Post a Comment