window install wsl and docker
if you have error when execute below command, please try connect to the mobile hotspot (if you can't access the external network, like google)
First, install wsl
(refer to https://learn.microsoft.com/en-us/windows/wsl/install, https://zhuanlan.zhihu.com/p/69121280):
execute below command in powershell using adminstrator
wsl --install
Enable-WindowsOptionalFeature -Online -FeatureName VirtualMachinePlatform
it will reboot your PC
wsl -v
wsl --update
If your windows(10/11) hasn't enable wsl, please enable wsl first( refer to https://blog.csdn.net/J835466742/article/details/128470256)
If you can not visit "https://raw.githubusercontent.com/microsoft/WSL/master/distributions/DistributionInfo.json", try another network, like your phone shared wifi.
then,you can find your Ubuntu in "Start", click it to finish the initialization.
Second, install docker in your Ubuntu
( refer to Running Docker-CE in WSL2. Recently, I started looking at… | by Michael Johanson | Medium)
execute below command:
sudo apt-get update
sudo apt-get install apt-transport-https ca-certificates curl software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
sudo apt-get install docker-ce
sudo gpasswd -a $USER docker
sudo service docker start
Install successfully!
do a test
docker run hello-world
if error like below
maybe you can exit and login again, then try again.
Third, share file between wsl and your PC
win+E, then input "\\wsl$" in the address bar, you can find your wsl
Forth, run redis and postgresql by docker
create a yml in wsl, then execute below command, then you can see your docker container
docker compose up
docker ps
in your wsl you can execute below command to directly run redis-cli
docker exec -it my_redis redis-cli
Fifth, visit your service in wsl in windows
we can use localhost to visit your service in wsl, if not, you can use wsl ip
find your wsl ip in wsl
use this ip , you can visit the service which run in your wsl