thanatos-vf-2000/vagrant-docker-wls2

Exemple of Vagrant and Docker in WSL2.

Installs: 0

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 1

Forks: 0

Open Issues: 0

Language:Dockerfile

Type:project

v1.0.0 2022-11-04 02:58 UTC

This package is auto-updated.

Last update: 2024-06-04 06:32:57 UTC


README

GitHub version

Latest Stable Version Total Downloads Latest Unstable Version License PHP Version Require

Exemple of Vagrant and Docker in WSL2

Docker installation on WSL

Installing Docker in WSL

# Installation requirements
sudo apt-get update
sudo apt-get install \
    apt-transport-https \
    ca-certificates \
    curl \
    gnupg \
    lsb-release

# Adding the Docker repo
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

# Adding the Docker repo key
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg

# Docker installation
sudo apt-get update && sudo apt-get install docker-ce docker-ce-cli containerd.io

# Add the current user to the Docker group
sudo usermod -aG docker $USER

Update IPTables

sudo update-alternatives --set iptables /usr/sbin/iptables-legacy
sudo update-alternatives --set ip6tables /usr/sbin/ip6tables-legacy

Create /etc/profile.d/vagrant.sh

sudo vi /etc/profile.d/vagrant.sh

Add this line to file

#https://developer.hashicorp.com/vagrant/docs/other/wsl
export PATH="$PATH:/mnt/c/Windows/System32/WindowsPowerShell/v1.0"
export PATH="$PATH:/mnt/c/Windows/System32"
export VAGRANT_WSL_ENABLE_WINDOWS_ACCESS="1"

change right to file Add this line to file

sudo chmod a+x /etc/profile.d/vagrant.sh
  • Under windows 11, you need to add these lines to /etc/wsl.conf

Edit file /etc/wsl.conf

sudo vi /etc/wsl.conf

Add this line

[boot]
command = "service docker start"

Run this command on cmd or powershell

wsl.exe --shutdown

Once the WSL machine is restarted, check that Docker is operational:

docker ps
  • Under Windows 10, you must add these lines to your .profile

Edit file .profile

vi ~/.profile

Add this lines and replace WSL_DISTRO_NAME1 by the image name

if service docker status 2>&1 | grep -q "is not running"; then
    wsl.exe -d "${WSL_DISTRO_NAME}" -u root -e /usr/sbin/service docker start >/dev/null 2>&1
fi

Run this command on cmd or powershell

wsl.exe --shutdown

Once the WSL machine is restarted, check that Docker is operational:

docker ps

Installation of Vagrant

Add repository and install

curl -fsSL https://apt.releases.hashicorp.com/gpg | sudo apt-key add -
sudo apt-add-repository "deb [arch=amd64] https://apt.releases.hashicorp.com $(lsb_release -cs) main"
sudo apt-get update && sudo apt-get install vagrant

Restart WSL, run this command on cmd or powershell

wsl.exe --shutdown

Images

  • Ubuntu
    • 14.04 - trusty
    • 16.04 - xenial
    • 18.04 - bionic
    • 20.04 - focal
    • 22.04 - jammy
    • 22.10 - kinetic
  • Windows

Footnotes

  1. run in powershell commande wsl -l -v