Skip to content

Commit

Permalink
Merge pull request codeedu#46 from codeedu/feature/improve-info
Browse files Browse the repository at this point in the history
feat: Add Docker Engine and Docker Desktop compatibility information …
  • Loading branch information
argentinaluiz authored Jul 29, 2024
2 parents 1f894af + d2e1527 commit 05ed9ca
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 8 deletions.
46 changes: 39 additions & 7 deletions README.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
* [Can I access applications running in WSL 2 from Windows?](#can-i-access-applications-running-in-wsl-2-from-windows)
* [Can I run graphical applications in WSL 2?](#can-i-run-graphical-applications-in-wsl-2)
* [Can I use WSL in production scenarios?](#can-i-use-wsl-in-production-scenarios)

* [Can I run Docker Engine alongside Docker Desktop?](#can-i-run-docker-engine-alongside-docker-desktop)


</details>
Expand Down Expand Up @@ -667,25 +667,53 @@ Typically, VHDX files are saved in `C:\Users\<your_user>\AppData\Local\Packages\
### Compressing the WSL 2 Virtual Disk
The WSL 2 virtual disk is a VHDX file that grows as you use Linux. If you delete files, the virtual disk does not automatically shrink; it will retain its size.
The WSL 2 virtual disk is a VHDX file that grows as you use Linux. If you delete files, the virtual disk does not automatically shrink; it will remain the same size.
To reduce the size, enable the `sparse` mode in WSL 2, which is automatic virtual disk compression. To enable it, edit the `.wslconfig` file:
To reduce its size, enable the `sparse` mode in WSL 2, which provides automatic disk compression. To enable it, edit the `.wslconfig` file:
```conf
[wsl2]
sparseVhd=true
```
This option only applies to new virtual disks. For existing virtual disks, run the command:
This option will only apply to new virtual disks.
For existing virtual disks, use the following commands:
```bash
wsl --manage "Ubuntu" --set-sparse true
wsl --manage "docker-desktop" --set-sparse true # If using Docker Desktop
```
This will convert the virtual disk to sparse mode, enabling automatic compression.
This will convert the virtual disk to sparse mode, which is automatic disk compression.
Before running the command, make sure the Linux distribution is stopped by using `wsl --shutdown` to stop all distributions.
If you have an old distribution and after applying sparse mode the virtual disk hasn't reduced in size, you can compress it manually.
Use the [wslcompact](https://github.com/okibcn/wslcompact) tool for this process. This tool is an executable for `PowerShell` that exports and imports the virtual disk, forcing WSL to compress it.
Run the command:
```bash
wslcompact -c Ubuntu
```
This will generate a new virtual disk named `ext4.vhdx`, which will be your compressed distribution. When the executable asks to register the disk, press `Y` and then `Enter`. This won't automatically register it; you'll need to do it manually as shown in the backup and restoration section of this tutorial.
Before running the command, ensure the Linux distribution is stopped by executing `wsl --shutdown` to stop all Linux distributions.
Remove the old disk with:
```bash
wsl --unregister Ubuntu
```
And register the new disk with:
```bash
wsl --import Ubuntu C:\path\to\ext4.vhdx
```
> **Warning**: Backup your Linux distribution before compressing it to avoid losing data in case of errors.
### LAN and VPN Network Mode
Expand Down Expand Up @@ -797,4 +825,8 @@ Yes, WSL 2 supports graphical applications through the WSLg (Windows Subsystem f
### Can I use WSL in production scenarios?
WSL is designed as a development tool and is not recommended for production use.
WSL is designed as a development tool and is not recommended for production use.
### Can I run Docker Engine alongside Docker Desktop?
No, you can only run one at a time. It is possible to have both installed, but only one can be running at any given time.
26 changes: 25 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
- [É possível acessar aplicações rodando no WSL 2 pelo Windows?](#é-possível-acessar-aplicações-rodando-no-wsl-2-pelo-windows)
- [É possível rodar aplicações gráficas no WSL 2?](#é-possível-rodar-aplicações-gráficas-no-wsl-2)
- [Posso usar o WSL em cenários de produção?](#posso-usar-o-wsl-em-cenários-de-produção)
- [Posso rodar o Docker Engine junto com o Docker Desktop?](#posso-rodar-o-docker-engine-junto-com-o-docker-desktop)
- [Quer configurar um ambiente mais produtivo no Windows?](#quer-configurar-um-ambiente-mais-produtivo-no-windows)

</details>
Expand Down Expand Up @@ -682,7 +683,9 @@ Para diminuir ative o modo `sparse` do WSL 2, que é a compactação automática
sparseVhd=true
```

Esta opção só funcionará para novos discos virtuais, para os discos virtuais já criados, execute o comando:
Esta opção só funcionará para novos discos virtuais.

Para os discos virtuais já criados, execute o comando:

```bash
wsl --manage "Ubuntu" --set-sparse true
Expand All @@ -693,6 +696,23 @@ Isto irá converter o disco virtual para o modo sparse, que é a compactação a

Antes de executar o comando, verifique se a distribuição Linux está parada, execute o comando `wsl --shutdown` para parar todas as distribuições Linux.

Se você já tinha uma distribuição antiga e após aplicar o modo sparse, o disco virtual não diminuiu, você pode compacta-lo manualmente.

Use a ferramenta [wslcompact](https://github.com/okibcn/wslcompact) para realizar este procedimento. Basicamente esta ferramenta será um executável ativo no `PowerShell` e ao executá-lo ele irá exportar e importar o disco virtual, forçando o WSL a compacta-lo.

Execute o comando:

```bash
wslcompact -c Ubuntu
```

Será gerado um novo disco virtual chamado de `ext4.vhdx` que será sua distribuição compactada. Quando o executável pedir para registar o disco, coloque `Y` e pressione `Enter`, isto não fará ele registrar, você deverá fazer isto manualmente como foi mostrado na seção de backup e restauração deste tutorial.

Remova o disco antigo com o comando `wsl --unregister Ubuntu` e registre o novo disco com o comando `wsl --import Ubuntu C:\caminho\ext4.vhdx`.

> Cuidado: Faça um backup da sua distribuição Linux antes de compacta-la, pois você pode cometer um erro e perder seu Linux.

### Rede em modo LAN e VPN

Como o WSL é virtualizado, há uma outra interface de rede, por isso se você usa rede LAN (cabeada), ao rodar aplicações e tentar acessar pelo navegador, por exemplo, você não conseguirá acessar. Seria necessário ficar fazendo binding de portas o que não seria produtivo.
Expand Down Expand Up @@ -803,6 +823,10 @@ Sim, este o projeto WSLg (Windows Subsystem for Linux GUI) que permite rodar apl

O WSL é uma ferramenta de desenvolvimento e não é recomendado para uso em produção.

### Posso rodar o Docker Engine junto com o Docker Desktop?

Não, só é possível rodar um de cada vez. É até possível ter os dois instalados, mas só um pode ser executado por vez.

### Quer configurar um ambiente mais produtivo no Windows?

Acesse os tutorias abaixo:
Expand Down

0 comments on commit 05ed9ca

Please sign in to comment.