A Peculiarly Vagrant Workaround for Docker and Windows Home
Created by josh
May 03, 2018 2:02:55 PM PDT (Revised
September 08, 2020 9:10:10 AM PDT
)
Docker doesn't support Windows Home as of yet - but we can make it work!
The first time I decided to get Docker going locally on my machine, I went to download Docker CE, and got to the installation. Then BOOM!
Installation failed: one pre-requisite is not fulfilled Docker for Windows requires Windows 10 Pro or Enterprise version 14393, or Windows server 2016 RTM to run |
Why I ought'a!
No worries. If you're familiar with Vagrant and how it works dependently on Windows with VirtualBox, there is a neat little workaround to get this running.
2) Create a new Vagrant box
I created a new folder in My Documents called "vagrant" and put the Vagrantfile there.
Here is an example file I use to get a Debian Jessie/64 VM running (just remember the mounted host directory has to be inside Vagrant's current working directory):
Vagrant.configure("2") do |config|
config.vm.box = "debian/jessie64"
config.vm.synced_folder "c:/path/to/vagrant/my/code", "/media/vagrant", type: "rsync"
config.vm.define "my-vm" do |my|
my.vm.hostname = 'my-vm'
my.vm.network "public_network", ip: "10.0.0.199"
my.vm.network :forwarded_port, guest: 80, host: 80
end
end
3) Using Powershell (or cmd I suppose could work), cd into your Vagrantfile directory.
4) Run
$ vagrant up
This can actually take a while sometimes. Go get some coffee, come back in a few.
Bringing machine 'my-vm' up with 'virtualbox' provider...
==> my-vm: Checking if box 'debian/jessie64' is up to date...
==> my-vm: Clearing any previously set forwarded ports...
==> my-vm: Clearing any previously set network interfaces...
==> my-vm: Preparing network interfaces based on configuration...
my-vm: Adapter 1: nat
my-vm: Adapter 2: bridged
==> my-vm: Forwarding ports...
my-vm: 8000 (guest) => 8000 (host) (adapter 1)
my-vm: 22 (guest) => 2222 (host) (adapter 1)
==> my-vm: Running 'pre-boot' VM customizations...
==> my-vm: Booting VM...
==> my-vm: Waiting for machine to boot. This may take a few minutes...
my-vm: SSH address: 127.0.0.1:2222
my-vm: SSH username: vagrant
my-vm: SSH auth method: private key
==> my-vm: Machine booted and ready!
==> my-vm: Checking for guest additions in VM...
my-vm: No guest additions were detected on the base box for this VM! Guest
my-vm: additions are required for forwarded ports, shared folders, host only
my-vm: networking, and more. If SSH fails on this machine, please install
my-vm: the guest additions and repackage the box to continue.
my-vm:
my-vm: This is not an error message; everything may continue to work properly,
my-vm: in which case you may ignore this message.
==> my-vm: Setting hostname...
==> my-vm: Configuring and enabling network interfaces...
==> my-vm: Rsyncing folder: /cygdrive/c/path/to/vagrant/ => /vagrant
==> my-vm: Rsyncing folder: /cygdrive/c/path/to/vagrant/my/code => /media/vagrant
==> my-vm: Machine already provisioned. Run `vagrant provision` or use the `--provision`
==> my-vm: flag to force provisioning. Provisioners marked to run always will still run.
==> my-vm: Machine 'my-vm' has a post `vagrant up` message. This is a message
==> my-vm: from the creator of the Vagrantfile, and not from Vagrant itself:
==> my-vm:
==> my-vm: Vanilla Debian box. See https://app.vagrantup.com/debian for help and bug reports
5) SSH into your Vagrant environment. If you have an SSH client, such as Putty - (or if you've hooked up Powershell with SSH), you can SSH localhost:2222 (user: vagrant, pw: vagrant). By far, the easiest way to accomplish an SSH session with your Vagrant instance is to run
$ vagrant ssh my-vm
The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.
Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
vagrant@my-vm:~$
From that point, you should be able to sudo su - and maintain a root session.
$ sudo su -
root@my-vm:~#
6) Install Docker CE from command line. I whipped up some instructions here on step #1.
In a separate Powershell window, I just change directory (cd) to my Vagrant working directory and run...
$ vagrant rsync-auto
... which sets up a watch dog for all file changes in the mounted host directory.
That's it! You can now use the /media/vagrant
directory, which essentially mounts your Windows directory via rsync, to utilize Docker development through the Vagrant instance.