DEV Community

Cover image for Windows VM Inside a Linux Docker Container
vaggeliskls
vaggeliskls

Posted on • Edited on

Windows VM Inside a Linux Docker Container

When it comes to creating reproducible and isolated development environments, two leading technologies reign: Docker and Vagrant. Docker facilitates containerization by bundling applications and dependencies together, making the applications platform-independent. On the other hand, Vagrant is a tool for virtual environments, allowing the creation and management of virtual machines (VMs). Running a Vagrant VM, particularly a Windows VM, inside a Docker container creates a unique combination that can offer remarkable benefits, especially in the field of Continuous Integration (CI) and Continuous Deployment (CD). 🔂 🚀

Today, we'll tap into an existing GitHub repository that demonstrates how to implement a Windows VM within this Docker/Vagrant setup. The repository can be found at the following URL: https://github.com/vaggeliskls/windows-in-docker-container

Prerequisites 📑

Before proceeding, the following tools should be installed on your system:

How to Use It 🛠️

  1. Create an environmental file .env with VMs specifications
# Vagrant image settings
MEMORY=8000 # 8GB
CPU=4
DISK_SIZE=100
Enter fullscreen mode Exit fullscreen mode
  1. Create a docker-compose.yml file
version: "3.9"

services:
  win10:
    image: docker.io/vaggeliskls/windows-in-docker-container:latest
    env_file: .env
    stdin_open: true
    tty: true
    privileged: true
    cap_add:
      - NET_ADMIN
      - SYS_ADMIN
    volumes:
      - /sys/fs/cgroup:/sys/fs/cgroup
    devices:
      - /dev/kvm
      - /dev/net/tun
    ports:
      - 3389:3389
Enter fullscreen mode Exit fullscreen mode
  1. Run: docker-compose up -d

Windows vm screenshot

Remote Desktop 🖥️

For debugging purposes or testing, you can always connect to the VM with remote desktop software products. Some software that used when developed was:

User login 👤

The default users based on vagrant image are

  • Administrator
    • Username: Administrator
    • Password: vagrant
  • User
    • Username: vagrant
    • Password: vagrant

Conclusion 👋

Running a Vagrant Windows VM inside a Docker container merges the benefits of Docker's platform-independent containerization with Vagrant's controlled, easy-to-manage development environments. Although such a setup won't fulfill every use case, understanding how Docker and Vagrant operate and interact is highly beneficial for DevOps professionals.

Remember, different configurations exist and this setup can be tweaked to suit specific application requirements. Be aware that running a VM inside a Docker container can be resource-intensive, so always check your system's specifications before proceeding. 📝

Happy coding!

References 📚

Top comments (0)