The smartest way to run docker on Windows 10 Home
In 2019, when docker announced support for Windows OS, I too rejoiced as a long term windows user but only to be disappointed later as it is supported only for Windows pro and ultimate versions which have Hyper-V virtualization. Docker is not supported for Windows 10 Home OS :(
Though there were many workarounds and hacks available to make docker work in Windows 10 Home, those were all exceptionally difficult.
But, All is Not Lost. Here I am going to show you how we can install and use Docker on Windows 10 Home easily
Requirements
- One Windows 10 Home (lol 😄 😄 )
- Oracle VirtualBox
- Chocolatey
Once you install VirtualBox and Chocolatey, follow the steps below to install and run docker
Step 1. Install docker using chocolatey
Open Windows PowerShell in admin mode and run the following command
> choco install docker-machine -y
verify chocolatey is installed properly in your computer
> choco --version
0.10.15
Step 2. create a docker-machine
Use the the `docker-machine` command to create a virtual machine in Oracle Virtual Box to run the docker containers in it. Open your favourite terminal and run the below command to create a new virtual machine.
docker-machine create
--driver virtualbox
--virtualbox-cpu-count "6"
--virtualbox-disk-size "20000"
--virtualbox-memory "8192"
docker-vm
More options for creating the virtual machine can be found here in this docker official documentation
Step 3. Verify and Set-up Environment Variables
Check the status of the docker-vm by running the command
$ docker-machine status docker-vm
Running
Next is setting environment variables, this is to dictate that docker
should run commands in our virtual machine. It is recommended to run this command every time we start the virtual machine after a shutdown.
$ docker-machine env docker-vm
SET DOCKER_TLS_VERIFY=1
SET DOCKER_HOST=tcp://192.168.99.100:2376
SET DOCKER_CERT_PATH=C:\Users\ramees\.docker\machine\machines\docker-vm
SET DOCKER_MACHINE_NAME=docker-vm
SET COMPOSE_CONVERT_WINDOWS_PATHS=true
REM Run this command to configure your shell:
REM @FOR /f "tokens=*" %i IN ('"C:\ProgramData\chocolatey\lib\docker-machine\bin\docker-machine.exe" env docker-vm') DO @%i
At the end of the output, it recommends executing the following command to have all variables available.
@FOR /f "tokens=*" %i IN ('"C:\ProgramData\chocolatey\lib\docker-machine\bin\docker-machine.exe" env docker-vm') DO @%i
These environment variables are only set for the current session of your terminal, you have to set them each time you restart and open a new terminal.
For setting permanent variables from the command line, use SETX
command. You can find more details and examples in this StackOverflow post
Another option is to manually add the above variables one by one.
Type “Advanced system settings” in the Windows search bar, click on “Environment Variables”, and add all variables displayed when you ran the command: docker-machine env
Step 4. Run a WordPress web app from docker-hub
Now everything is set up and ready to go... Let's have some fun time. We are going to run a WordPress web app in our brand new docker server by running a couple of commands
$ docker pull wordpress$ docker run --name some-wordpress -p 8080:80 -d wordpress
This will start a webserver in the virtual machine on port:8080
. To access this from our Windows machine, we need to do a final configuration in the VirtualBox for port-forwarding under the network configurations section.
Now open your favourite browser and go to this link http://localhost:8080 and have fun
Step 5. Stopping a docker-machine
Okay, now we don't want our docker virtual machine to be running unnecessarily and consume all the system resources after we finish all our work. So it is recommended stopping the docker virtual machine by running the below command after we finish our tasks
docker-machine stop docker-vm
At this point, you all set to develop your shiny new application with docker. You can find more resources on how to develop with docker here in this official docker documentation
For more articles and insights, follow me on LinkedIn.