You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# Install Docker on Windows Subsystem for Linux (WSL)
2
2
3
3
If you do not already have Windows Subsystem for Linux (WSL) installed, see [Install Linux on Windows with WSL](https://docs.microsoft.com/en-us/windows/wsl/install) for instructions.
4
4
@@ -34,28 +34,44 @@ wsl --list --verbose
34
34
wsl --set-version "YOUR_DISTRO_HERE" 2
35
35
```
36
36
37
+
??? bug "WSL commands only output usage instructions"
38
+
39
+
If the `wsl` command outputs usage instructions instead of the expected output regardless of given parameters, ensure that your system has following Windows features enabled:
40
+
41
+
- Windows Subsystem for Linux
42
+
- Virtual Machine Platform
43
+
- Hyper-V
44
+
45
+
To do this, open the _Turn Windows Features on or off_ dialog from _Start_ menu, Settings, or Control Panel, and ensure that the features mentioned above are selected.
46
+
37
47
## Install recent version of Ubuntu
38
48
39
-
Install recent version of Ubuntu from either Microsoft Store or PowerShell. These instructions use Ubuntu 22.04. Other distributions might also work, if you know what you are doing.
49
+
Install recent version of Ubuntu from either Microsoft Store or PowerShell. These instructions use Ubuntu 24.04. Other distributions might also work, if you know what you are doing.
40
50
41
-
If you want to install distro through the PowerShell, run `wsl --list --online` and follow the instructions.
51
+
=== "PowerShell"
42
52
43
-
```pwsh
44
-
wsl --list --online
45
-
wsl --install -d Ubuntu-24.04
46
-
```
53
+
If you want to install distro through the PowerShell, run `wsl --list --online` and follow the instructions:
54
+
55
+
```pwsh
56
+
wsl --list --online
57
+
wsl --install -d Ubuntu-24.04
58
+
```
59
+
60
+
=== "Microsoft Store"
61
+
62
+
If you want to install distro through Microsoft Store: Open Microsoft Store, search for `Ubuntu 24`, select _Ubuntu 24.04 LTS_, and click _Install_.
47
63
48
-
If you want to install distro through Microsoft Store: Open Microsoft Store, search for `Ubuntu 22`, select _Ubuntu 22.04 LTS_, and click _Install_.
64
+
---
49
65
50
-
If not opened automatically, open the installed Ubuntu distro and follow instruction in installation wizard.
66
+
If not launched automatically, open the installed Ubuntu distro (e.g., by clicking it in the _Start_ menu) and follow instruction in installation wizard. You will have to choose an username and a password to use in the WSL instance. To make your life easier, use only lowercase letters and numbers in your Linux username.
51
67
52
68
## Install Docker
53
69
54
70
Open Ubuntu you just installed and follow [Install Docker Engine on Ubuntu](https://docs.docker.com/engine/install/ubuntu/) instructions.
55
71
56
72
__tl;dr:__ Run the convenience script available in `get.docker.com`:
@@ -64,21 +80,45 @@ Ignore the `WSL DETECTED: We recommend using Docker Desktop for Windows.` warnin
64
80
65
81
To be able to run docker commands without `sudo`, add current user to `docker` group with `usermod`. Note that you might have to logout and login for the changes to take effect.
66
82
67
-
```bash
83
+
```sh
68
84
sudo usermod -aG docker $USER
69
85
```
70
86
71
87
## Configure networking
72
88
73
89
By default, WSL 2 uses local DNS server to reflect network settings, such as VPN, from the host Windows to WSL instances. The IP address of this DNS server might fall into IP range used by the Dockers default bridge network. In that case, containers will not be able to resolve domains.
74
90
75
-
To configure working DNS inside containers you can either use public DNS or modify IP range used by Dockers default network. If you are working behind a corporate firewall, public DNS might not work.
91
+
To configure working DNS inside containers you can either modify IP range used by Dockers default network or use public DNS. If you are working behind a corporate firewall, public DNS might not work.
92
+
93
+
=== "Configure IP range for Docker"
94
+
95
+
To configure Docker to use IP ranges that wont overlap with DNS server configured by WSL, add following content to `/etc/docker/daemon.json`, for example, by opening it with `sudo nano /etc/docker/daemon.json`:
96
+
97
+
```json title="/etc/docker/daemon.json"
98
+
{
99
+
"bip": "172.21.0.1/16",
100
+
"default-address-pools": [
101
+
{
102
+
"base":"172.22.0.0/16",
103
+
"size":24
104
+
}
105
+
]
106
+
}
107
+
```
108
+
109
+
If you already have dockerd running, you have to restart it for the changes to take effect.
110
+
111
+
```sh
112
+
sudo service docker restart
113
+
```
114
+
115
+
If containers cannot resolve domains or have other issues with internet access with above configuration, ensure that the above networks do not overlap with network interface configured by WSL. To do this, run `ip a` or `ifconfig` command ( or `ipconfig` in powershell) and check the IP address assigned for `eth0` interface it output. If the second part of the IP address matches either IP block defined in the above configuration, change the value in `/etc/docker/daemon.json`. Any private IP v4 address block should work. You can use, for example, some blocks between `172.16.0.0/16` and `172.31.0.0/16`, i.e., change the second part of the IP address.
76
116
77
117
=== "Use public DNS in WSL 2"
78
118
79
119
To use public DNS, you must first disable WSL from automatically generating DNS settings to `/etc/resolv.conf`. To do this, add following rows to `/etc/wsl.conf` file in your WSL instance, for example, by editing (or creating) it with `sudo nano /etc/wsl.conf`:
80
120
81
-
```conf
121
+
```conf title="/etc/wsl.conf"
82
122
[network]
83
123
generateResolvConf = false
84
124
```
@@ -91,58 +131,46 @@ To configure working DNS inside containers you can either use public DNS or modi
91
131
92
132
Finally, configure DNS server manually by creating `/etc/resolv.conf` with following content, for example by opening it with `sudo nano /etc/resolv.conf`:
93
133
94
-
```conf
134
+
```conf title="/etc/resolv.conf"
95
135
nameserver 8.8.8.8
96
136
```
97
137
98
-
=== "Configure IP range for Docker"
138
+
---
99
139
100
-
To configure Docker to use IP ranges that wont overlap with DNS server configured by WSL, add following content to `/etc/docker/daemon.json`, for example, by opening it with `sudo nano /etc/docker/daemon.json`:
140
+
## Ensure Docker daemon is running
101
141
102
-
```json
103
-
{
104
-
"bip": "172.21.0.1/16",
105
-
"default-address-pools": [
106
-
{
107
-
"base":"172.22.0.0/16",
108
-
"size":24
109
-
}
110
-
]
111
-
}
112
-
```
113
-
114
-
If you already have dockerd running, you have to restart it for the changes to take effect.
115
-
116
-
```bash
117
-
sudo service docker restart
118
-
```
142
+
Recent version of WSL enable systemd by default. In this case, Docker daemon should be started automatically when ever WSL is running. To verify Docker has been started, run the hello-world container:
119
143
120
-
If containers cannot resolve domains with above configuration, ensure that the above networks do not overlap with the DNS server configured by WSL by running `ipconfig` in powershell and checking the networks it outputs.
121
-
122
-
## Start Docker daemon
144
+
```sh
145
+
docker run hello-world
146
+
```
123
147
124
-
Start`dockerd` as a background process by using `service` or, alternatively, start `dockerd` directly.
148
+
If Docker was not started automatically, start`dockerd` as a background process by using `service` or, alternatively, start `dockerd` directly.
125
149
126
-
```bash
150
+
```sh
127
151
sudo service docker start
128
152
```
129
153
130
-
Note that this must be done every time WSL is restarted. If `docker` commands print `Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?` error, run `sudo service docker status` command to check if `dockerd` is running and, if necessary, run `sudo service docker start` command again.
154
+
If `docker` commands print `Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?` error, run `sudo service docker status` command to check if `dockerd` is running and, if necessary, run `sudo service docker start` command to start the Docker service.
131
155
132
-
If you are working on Windows 11, you can use [boot settings](https://docs.microsoft.com/en-us/windows/wsl/wsl-config#boot-settings) to start Docker daemon automatically on WSL instance startup. To do this, add following rows to `/etc/wsl.conf` file in your WSL instance, for example, by editing (or creating) it with `sudo nano /etc/wsl.conf`.
156
+
??? example "Launch docker with boot settings"
133
157
134
-
```conf
135
-
[boot]
136
-
command = service docker start
137
-
```
158
+
If you are working on earlier version of Windows 11, you can use [boot settings](https://docs.microsoft.com/en-us/windows/wsl/wsl-config#boot-settings) to start Docker daemon automatically on WSL instance startup. To do this, add following rows to `/etc/wsl.conf` file in your WSL instance, for example, by editing (or creating) it with `sudo nano /etc/wsl.conf`.
159
+
160
+
```conf title="/etc/wsl.conf"
161
+
[boot]
162
+
command = service docker start
163
+
```
164
+
165
+
Note that this should not be done if systemd is enabled.
138
166
139
167
## Install Docker compose
140
168
141
169
Follow [Install Docker Compose](https://docs.docker.com/compose/install/) instructions for Linux.
142
170
143
171
__tl;dr:__ Install Docker Compose with the distros package manager:
0 commit comments