Boot up Linux development env using Vagrant
Docker Desktop | Linuxdev with Vagrant | |
---|---|---|
Docker hub account | signin is required if you want to stop checking updates | ✅login to Docker hub is not necessary |
Control over the Docker Engine Version | Should use latest above v3, unless the user ignore the updates | ✅have the controll for docker-ce (community edition) |
Licensing | free for small business and personal, but auto-checking-update | ✅free of charge (w/o VB extension pack) |
Network setup | Host network | ✅Can Choose . Bridge(host) . NAT + Host-only |
Performance | . Hyper-v VM; might be slightly better but it likely consumes more memory | . Virtualbox VM; not so bad . Has alternatives (Hyper-v/VMWare/Virtualbox) |
Environment | Slightly different environment between . Windows WSL2 (Custom distro integration required for Docker host access) . Windows VM (w/o Docker host acess) . Mac VM (w/o Docker host acess) |
✅Common Linux environment available in Mac/Windows . Full Linux VM will be provided as a Docker host (Files can be shared natively in Linux host) . Docker engine can be also accessed from the host OS (docker and docker-compose client installation required) |
Installation | Installer provided | Install scripts provided |
Starting Docker | Autostart configurable | Startup script is provided both for Windows and Mac |
Clients | Provided along with the Docker Desktop installer | Install scripts provided |
Config | ✅Configurable in GUI | Configurable in script |
Docker storage | Configurable size | ✅Configurable 2k block size with a lot of inodes |
Logs/status | ✅GUI provided | Only available in CLI |
Limiting memory usuage | .wslconfig file for WSL2/GUI for VM | .env file/VirtualBox GUI |
Some recent windows update enables VBS and it will turn on hyper-v and that would make Vrtualbox slow and unstable.
If systeminfo
command shows following at the bottom, it's good to use Virtualbox.
Hyper-V Requirements: VM Monitor Mode Extensions: Yes
Virtualization Enabled In Firmware: Yes
Second Level Address Translation: Yes
Data Execution Prevention Available: Yes
Pease follow he issue for further guidance.
Docker is necessary for developing nowadays. But if you are not using Linux as the OS, it requires VM for Docker engine.
I was using Linux in Virtualbox for many years and found that was quite nice and had no problem for using docker in it. And personally satisfied with the performance of docker in VM In the other hand, Docker Desktop, I found couple of issue with using Docker Desktop in Windows recently.
What I didn't like about WSL/Docker Desktop
- Memory usage is keep growing upto VM memory limitation
- some file was missing for binding into docker
- Additional settings to ssh in to the linux
- ssh connection env was a bit different (not sure) when used in terminal
- X client was blocked by Windows Firewall
- not sure what it was but felt heavy
- Watching files in the host is not working
- Hyper-v is not returning unused memory frequently so the host can be struggling with memory.
So it's generally recommended to use WSL2 Ubunu but I would rather use VM
- Virtualbox seems to be able to run many containers more stable and does not apply much pressure to the host memory. (compared to WSL2)
- Generally there are less issues in developing in Linux than Windows (Same reason to use WSL2)
- Full configurable linux host (docker)
- USB ports can be used directly in VM (Note: USB3 in VB is available in the extension pack, which is free for only personal users)
Not only for the Windows users, there would be some advantage for Mac users as well
- Easily backup/cleanup VM/dev env
- The dev env is a sandbox
- A reference environment for Linux env
- Run linux GUI apps using X server and tunneling
- Docker is running Linux VM already, why not?
- Multiple network interfaces available
And if you are familiar with the Linux command line, using Linux makes more senses than using Docker Desktop.
- Share VM when you need to bootcamp to windows
- Access to docker host
- Unlimited access to host(Linux VM) root directory
- Faster host(Linux VM) volume sharing
- Free
For comparison, I tried one of my project which builds multiple docker images with node.js and filling up 20GB of docker storage.
Building includes installing node packages and webpack. Docker build kit was used for cache mounting.
Env | Build Time | Note |
---|---|---|
Linuxdev (Windows host) 6GB, i7 4 cores |
24m 12s | |
WSL2 (Docker Descktop) 16GB, i7 6 cores (no .wslconfig) |
19m 18s | spent up to 13GB |
WSL2 (Docker Descktop) 8GB, i7 6 cores (with .wslconfig) |
18m 22s | |
Linuxdev (Windows host) 8GB , i7 6 cores |
✅ 14m 39s | |
Mac OSX (Docker Descktop) 8GB, i7 6 cores |
19m 37s | First build failed after 1 hour |
Linuxdev (Windows host) 8GB , i7 4 cores |
21m 13s |
This was just an instance of the build. Just to let you know. As you noticed, Linuxdev was the best in some situation.
The script will disable Hyper-v (WSL2) and replace with VM and you can also use Docker from the host OS
- Unzip or git clone this repo
- Run setup scripts
- Windows
- Install host dependencies and dev tools
- Open powershell as Admin and run
Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass
: enables ps1 for this powersell processsetup.ps1
- This might require rebooting.
- Open powershell as Admin and run
- Bootup vagrant with provision
- Open terminal (git bash) and run
bootstrap.sh
- Open terminal (git bash) and run
- Install host dependencies and dev tools
- Mac
- Install host dependencies and dev tools
- Open teminal and run
setup.sh
- Open teminal and run
- Bootup vagrant with provision
- continue to run
bootstrap.sh
- continue to run
- Install host dependencies and dev tools
- Windows
- Wait until bootstrap.sh does
- input username to use in the VM
- Install Debian Linux 10.10
- Install Docker v20.10.8 (configurable in config/env_var.sh; remove VERSION if you want the latest)
- Install docker-compose (v1.29.2; configurable in .env
__VM__COMPOSE_VERSION
) - Create a user with UID 1000 and sudoer
- ohmyzsh
- expose samba share,
Projects
- generate id_rsa key and show public key
- add ssh config for linuxdev
- generate docker certificates and set bash variables
It's okay to repeat this bootstrap script if something went wrong.
Copy and paste ssh public key to use in Github and where ever it's required.
Now you can ssh into Linux dev env
ssh linuxdev
and you can also run any linux commands from the host terminal
ssh linuxdev -t echo hello from VM
For Windows Terminal, there is also a profile generated for the machine.
An additional external configuration dotfiles project like this can be added
If DOTFILES_REPO has been defined in .env
, it clones the repo to ~/dotfiles and try to run
- bootstrap*
- init*
- install*
- setup*
any of files which is executable.
setup.ps1
(Windows Powershell script; Use setup.sh for Mac)
bootstrap.sh
(Mac; You can also use it in Git bash in Windows Terminal)
- vagrant
- virtualbox
- vscode
- git
- Windows Terminal (Windows)
- iterm2 (Mac)
- gnu-sed (Mac)
- and so on...
- docker (installed by vagrant provision)
- docker-compose
- python3-pip
- git
- zsh
- oh-my-zsh
- vim-gtk (for vim-python3)
- dnsutils
- and so on...
This vm provides docker connection in 2376
port.
If you have docker client and set the env vars you can use docker from the host like Docker Desktop.
You can also install docker and docker-compose by running install-docker-clients script.
.bashrc
or .zshrc
has DOCKER_HOST and required variables for Mac/Git-bash and docker_env.bat
will set variables in the command terminal in Windows.
Bootstrap installes the required variables automaticaly so you can use docker straightaway.
- Share virtualbox env across Bootcamp
- Provide recommended fonts with Powerline patch