Hey Docker! Why do you hate Windows so much?
Are you using Windows? Are you using Docker? Your life is in danger! Going further that direction might create strong anxiety and mental disorder. If you are able to observe symptoms (Docker + Windows) do not ignore them. Those are life-threatening symptoms. To avoid further, irreversible damage read below.
This guide is dedicated for you dear stranger. If you are installing databases, indexes, custom images and other docker goodies like docker-compose or Dockerfile, you are in the right place. If you are doing this on Windows OS and continuously struggling, the solution is just in front of you. This guide will help you setup all of that in a way that it’s working fine. By working fine, I mean support you. Help you. Save your time. Use in pleasure. Simple and straightforward. Not looking for solutions or workarounds over and over again.
That’s not all, this solution solves all those annoying problems like:
- I cannot make docker volumes up and running
- My VPN software is making some issues with containers
- Volume or network command in docker-compose is just not working
- I have some issues with Windows 7/8/10+
- I have a Corporate laptop and Docker is just … (this is serious)
- I am using a Corporate VPN (like PulseSecure or other jewels) which is making some weird issues with networking
- I would love to play with Kubernetes but (see points above)
- and more …
If you are one of these very few happy people who use Docker Toolbox or Docker for Windows in default, recommended way and you are still happy. I’m glad, I’m happy for you as well. Otherwise, please stay with me.
Just to be clear. The Docker is an amazing piece of software, a game changer in many aspects which I’m not going to cover in this article.
Remember. If you have issues with Docker on Windows then you are not alone.
Your coworker, boss, family. Everybody might have problems with the Docker. You can save them. You can help them. You can change their daily experience from unpleasant/mediocre to unique/astonishing.
If you don’t know how to recognize people who are affected by the Docker on Windows issues, ask them: “What are the best practices you suggest”, they should answer something like:
- “If it eventually works, don’t touch”
- “Not everything is working, live with that”
- “Don’t use Docker on Windows if you don’t have to”
- “Be afraid when installing any Docker tooling”
- “Take a few days off before and some solid vacation after installing Docker”
- “…” - Silence as the expression of pain and wasted hours on the configuration of the environment.
Sneak peek into the release process of Docker for Windows
If you are wondering how the public release of the Docker looked like, here is the recorded conversation between the person responsible for putting this to the public audience (Boss) and the person responsible for implementation (Dev).
Dev: We have a lot of problems with the installation, volume mounts, networks, VPN and…
Boss: Ship it!
Dev: But the Windows users are going to hate us.
If for some reason you think that Docker for Windows on Hyper-V is solving all of the issues. Then, how to say it. No, it does not. I’m writing this guide for people who cannot use Hyper-V or usage of Docker for Windows imply some constraint which is not acceptable. No matter what you install, you eventually might hit one of those:
- Problems with sharing a volume on Docker Toolbox
- Problems with volumes mount on Windows 7
- Problems with docker installation when using Corporate VPN
- Problems with docker and PulseSecure
- When is ‘VPN Compatibility Mode’ going to be enabled?
- With Pulse turned off, the connection is fine. What can I do?
- Shared folders on VirtualBox driver does not work
- BSOD, sponsored by Hyper-V
- and more a lot more …
Ladies and gentlemen, I would like to present the solution that is resolving all of the Docker challenges. If you have an issue that is not solved by the guide, then I wish you luck in further searching.
The ultimate solution, the cure, salvation of many
Before we start, you need to you prepare a few things on your PC. Below, the comprehensive list of applications that you need to install before we can start. Be prepared, the list is really long:
Ok, now, when everything is installed, we are ready to go.
1) Create a VM and install Ubuntu
Create a VM with at least 2GB of RAM, maybe more if you like to use some bigger containers like Oracle DB (then hit at least 4GB+), to be safe you can start at 6GB. Install the Ubuntu LTS which is older than 6 months. Why not fresh LTS that just came out? I’ve hit some shared folders issues when Linux was too fresh. You might also encounter some breaking changes in the system which are making some of the documentation or approaches that you find online obsolete. We want to make our environment rock solid. Just download the LTS Linux and perform the installation.
2) Install docker and docker-compose
Note: At the moment of writing, this information is up to date, but it’s always good to reach the official documentation and read about the recommended approach.
Before you run “apt install” and ruin your day, stop. Use the official get-docker.sh script. For a very long time, the version that you could reach via apt was dead old. Now it’s better, but still, it’s not a good idea. There is a reason why the official Docker docs are not suggesting going that way. You can use the official installation script via:
$ curl -fsSL https://get.docker.com -o get-docker.sh
$ sudo sh get-docker.sh
We can use snap to install docker-compose. Just snap it.
$ sudo snap install docker-compose
3) Share your workspace with VM
I’m keeping my projects files in C:\work. Therefore, everything which I would need to access/copy/move/execute is there. Let’s share that directory with the VM. Open the VirtualBox and mount directory.
The location appears as /media/sf_work on Linux machine. Please keep in mind that only sudo from the VM can access this.
Everything will be local to the VM (this is going to be a game changer). To expose some container to your Windows OS, you have to forward the ports in the VM. This way you will be able to access the container via localhost.
We are almost there.
Congratulations! You have a fully working surprise-free, uber-productive Docker environment
Every docker command is executed within the Linux shell natively. There is no proxy. No more questions like:
- “Ok, so how I should translate this command to the PowerShell/Cygwin/Git-bash variant?”
- “How to write this script to work fine between the Linux/Windows?“
- “Why my docker commands are no longer working?”
Bonus: You have a fully working autocomplete for all of the docker commands.
*4) UI achievement unlocked!
If you managed to get to this point, there is another neat element. You can manage your container, images and entire docker environment via browser from the Windows OS. This way, you can run your VM in headless mode in many cases.
- Run the
$ docker volume create portainer_data
$ docker run -d -p 9000:9000 -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer
- Forward port 9000
- Open http://localhost:9000 on the Windows Box.
- Bonus: Select restart policy to “Always” so the portainer is going to be available immediately after the VM start. No need to run it manually every time you reboot the VM.
**5) Secret chapter, handy stuff.
When you have your virtual machine in place and you control how it’s working you can use some standard VM goodies:
- Pause/Unpause the VM. I’m using some heavy containers on the local dev Box (like Oracle 12c). It‘s very handy to sometimes pause the VM in order to free some RAM/CPU resources.
- Save the state. Instead of shutting down and start the VM, you can just save the state. This way you will have all your docker state frozen until you get back the other day.
- You have a fully working Linux machine which you can use for other stuff during the development. Like, displaying the train!
[INFO] BUILD SUCCESS
[INFO] BUILD SUCCESS
If you are using Maven, you will find the header above hilarious, right?
Lovely! The solution presented above was the only one that actually works for me in multiple projects regardless of the use case. Running tests, setup environment, running some handy scripts. The fact, that I can reuse Linux bash scripts, the full power of docker environment directly without any additional effort like translating to Powershell or Network/Volume hack saved me a tremendous amount of time. I wish that official Docker documentation would suggest that approach in the first place.
Thank you for reading,
Greg, Open Tangerine