Wsl2 & docker & postgresql 安装
WSL 是 Windows Subsystem for Linux 的缩写,是 Windows 系统的 Linux 子系统。
1 Install Docker and WSL 2 on Windows
- Install the latest Docker Desktop in Windows: https://docs.docker.com/docker-for-windows/install/. N.B. Old versions may not support WSL integration.
- Install WSL 2: https://docs.microsoft.com/en-us/windows/wsl/install-win10:
- Make sure the optional WSL feature is enabled. Open Powershell as Administrator and run:
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
- Enable virtual machine feature. Type Windows key and search “windows features”. Select “Virtual Machine Platform”. Close the window and restart Windows. Alternatively, open Powershell as Administrator and run:
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
- Download the Linux kernel update package: https://wslstorestorage.blob.core.windows.net/wslblob/wsl_update_x64.msi and install.
- Download and install Ubuntu 20.04 LTS in Macrosoft Store.
- Set WSL 2 as your default version. Open Powershell as Administrator and run:
wsl --set-default-version 2
2 Fix network in WSL 2
As a known bug in old Windows builds, the WSL 2 may not have Internet connection. Try pinging an external host within your WSL terminal, e.g.
ping google.com
$ ping google.com
64 bytes from arn09s10-in-f142.1e100.net (216.58.211.142): icmp_seq=1 ttl=115 time=27.9 ms
64 bytes from arn09s10-in-f142.1e100.net (216.58.211.142): icmp_seq=2 ttl=115 time=24.8 ms
64 bytes from arn09s10-in-f142.1e100.net (216.58.211.142): icmp_seq=3 ttl=115 time=22.3 ms
64 bytes from arn09s10-in-f142.1e100.net (216.58.211.142): icmp_seq=4 ttl=115 time=22.8 ms
If your ping received pongs, then you are all set, skip the following steps in this section. If not, follow the steps below to fix the network in WSL 2:
- Create a file: /etc/wsl.conf
$ sudo vim /etc/wsl.conf
- Put the following lines in the file
[network]
generateResolvConf = false
- In Powershell on your Windows, shutdown WSL 2:
wsl --shutdown
- Restart WSL 2
- Sudo remove the current
/etc/resolv.conf
file and create a new as sudo and add the following content:
nameserver x.x.x.x
nameserver y.y.y.y
nameserver z.z.z.z
nameserver 8.8.8.8
Replace x.x.x.x
, y.y.y.y
, and z.z.z.z
with your system’s IPv4 DNS server addresses (add more lines if you have more).
To find the list of DNS servers, first ensure your are connected to the VPN. Then go to your current network’s properties, under IPv4 DNS Servers retrieve the list of all active DNS servers you are using.
- Now WSL 2 should have network. Test
sudo apt update
orping www.google.com
- If the network still does not work, reboot your Windows and try it again.
3 Enable WSL integration in Docker Desktop
Run Docker Desktop on Windows and open the Settings window. In Settings/Resources/WSL INTEGRATION
, make sure Enable integration with my default WSL distro
is ticked. Docker Desktop must be running in order to make Docker in WSL 2 work.
4 Install Docker, Docker-compose, and Postgresql inside WSL 2
- Install Docker: https://docs.docker.com/engine/install/ubuntu/
- As an optional step, add own user to docker group so that you can run Docker without sudo:
sudo groupadd docker (If the Docker group does not exist)
sudo gpasswd -a $USER docker
newgrp docker
Then test with docker run hello-world
- Install Docker-compose: https://docs.docker.com/compose/install/
- Install Postgresql: https://www.postgresql.org/download/linux/ubuntu/. Note that Postgresql exists in Ubuntu 20.04 by default, but it is not the latest version and some features like pg_dump may not be supported. 5 Verify that you have pg_dump and psql installed:
pg_dump --version
psql --version
#待整理笔记