Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Vagrant.configure("2") do |config|
- config.vm.box = "bento/ubuntu-22.04"
- config.vm.provision "shell", inline: <<-SHELL
- # Update system and install Kubuntu desktop
- sudo apt-get update
- sudo apt-get install -y kubuntu-desktop sddm
- # Set GUI as default boot mode
- sudo systemctl set-default graphical.target
- sudo systemctl enable --now sddm
- # Install VirtualBox Guest Additions
- sudo apt-get install -y build-essential dkms linux-headers-$(uname -r)
- sudo apt-get install -y virtualbox-guest-dkms virtualbox-guest-utils virtualbox-guest-x11
- # Enable VirtualBox services
- sudo systemctl enable vboxadd.service
- sudo systemctl start vboxadd.service
- # Install VS Code
- wget -qO- https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > packages.microsoft.gpg
- sudo install -D -o root -g root -m 644 packages.microsoft.gpg /etc/apt/keyrings/
- echo "deb [arch=amd64 signed-by=/etc/apt/keyrings/packages.microsoft.gpg] https://packages.microsoft.com/repos/code stable main" | sudo tee /etc/apt/sources.list.d/vscode.list
- sudo apt update
- sudo apt install -y code
- # Enable automatic login to KDE
- echo -e "[Autologin]\nUser=vagrant\nSession=plasma.desktop" | sudo tee /etc/sddm.conf.d/autologin.conf
- # Install Docker CLI inside the VM
- sudo apt-get install -y docker.io
- sudo usermod -aG docker vagrant
- # Ensure the docker socket is correctly owned
- if [ -S /var/run/docker.sock ]; then
- sudo chown root:docker /var/run/docker.sock
- sudo chmod 666 /var/run/docker.sock
- fi
- # Create a systemd service to manually bind the host Docker socket
- cat <<EOF | sudo tee /etc/systemd/system/mount-docker-socket.service
- [Unit]
- Description=Bind-mount host Docker socket into VM
- After=network.target
- Requires=network-online.target
- Wants=network-online.target
- Before=docker.service
- [Service]
- Type=oneshot
- ExecStart=/bin/mount --bind /mnt/docker.sock /var/run/docker.sock
- RemainAfterExit=true
- ExecStop=/bin/umount /var/run/docker.sock
- [Install]
- WantedBy=multi-user.target
- EOF
- # Enable the Docker socket mount service
- sudo systemctl daemon-reload
- sudo systemctl enable --now mount-docker-socket
- SHELL
- # Configure VM resources
- config.vm.provider "virtualbox" do |vb|
- vb.gui = true
- vb.memory = "4096"
- vb.cpus = 2
- vb.customize ["modifyvm", :id, "--vram", "128"]
- vb.customize ["modifyvm", :id, "--accelerate3d", "on"]
- end
- # Shared folder for file exchange between host and VM
- config.vm.synced_folder "/home/umur", "/home/vagrant/host_share",
- owner: "vagrant",
- group: "vagrant",
- mount_options: ["dmode=775,fmode=664"]
- # Conditionally mount the Docker socket if it exists
- if File.exist?("/var/run/docker.sock")
- config.vm.synced_folder "/var/run/docker.sock", "/mnt/docker.sock", type: "virtualbox"
- else
- puts "WARNING: Docker socket not found on host. Skipping mount."
- end
- end
Advertisement
Comments
-
- This VM allows me to run VS Code projects that are docker integrated
Add Comment
Please, Sign In to add comment
Advertisement