Docker (and, more broadly, the technology of containerisation) has become an indispensable tool for developers. If you're looking to bundle your code into a container, it's highly likely you'll be wanting to use Docker. Docker Desktop is a software for managing your container images - available for free for non-enterprise customers. However, you may be looking to use Docker from the command line - and the good news is, you can! In this post, I'll run you through how to set up Docker Engine on Windows 10. This post will be especially useful if you are a complete beginner to using Docker and Linux.
Reasons for using Docker without Docker Desktop
In this post we will be setting up Docker Engine, but you should first ask yourself: do I need to go to this hassle? Docker Desktop runs Docker Engine under the hood anyway, but with a helpful GUI. It is arguably the best way to work with Docker. For a newcomer with little Linux experience, working with Docker Engine through CLI might be a bit intimidating. To see if it's really for you, I'll give you the reasons I chose to run Docker without Docker Desktop:
- Storage: I wasn't keen to add another software to my laptop, one that wouldn't get used much and just contribute to laptop slowdown. Installing Docker Engine was a more lightweight alternative.
- Usage: I didn't see myself working with Docker too often for my usecases (for now), so I didn't mind dealing with working only through the CLI.
- Learning Experience: To be honest, the main reason I configured Docker without Docker Engine was for the learning experience. I've installed software through packaged installers many times, but at the time my Linux experience was minimal, so I saw it as a good learning opportunity.
If you've gotten this far and still want to go ahead with this, then read on!
Step 1: Activate Windows Subsystem for Linux (WSL)
Head to the Microsoft Store and download Windows Subsystem for Linux. This version comes preloaded with Linux's “systemd” suite, which we're going to need.
Step 2: Install a Linux Distribution
Next up, we're going to need a Linux distribution. You could use any here, but for simplicity I recommend you go with Ubuntu. Grab the latest version from the Microsoft store.
Step 3: Launch and Set Up Ubuntu
Launch Ubuntu from the start menu. It will do a bit of setting up, then ask you to create a User and Password. If you're fully new to Linux, think of this as the equivalent to your Windows user account login. Careful - Linux doesn't show the cursor or what you've typed when you're typing the password - so don't get confused if you don't see anything changing.
Step 4: Update Ubuntu APT
Before doing anything, it's a good idea to update the Ubuntu APT repository (a package manager for Ubuntu). Run sudo apt update. For information, sudo is short for “super-user do”.
Step 5: Install Docker Engine
We now have a working Ubuntu subsystem. So to install Docker Engine, we refer to the installation instructions on the Docker docs. Docker provide a convenience script, which tailors the docker installation to your Linux distribution. Simply run the two commands, ensuring you use sudo for the second one. This will install Docker Engine in your Linux distribution.
Note: I recommend getting the script from the provided link, rather than my snip above, as it may change in the future.
Step 6: Create Docker User
Now that we have Docker Engine installed, we need to give our user access to use it. To do so, run sudo usermod -aG docker $User. Replace $User with the user name you created.
Step 7: Verify Installation
To check everything went according to plan, there are a few steps to take. Firstly, run docker --version. If you get any response, you have Docker installed.
Next open up Powershell and shutdown WSL by typing wsl --shutdown.
Wait ~10 seconds, then start Ubuntu up again and run docker run hello-world. If you get the below output, then congratulations - you've done it! I'm really proud of you.
To use Docker, simply run the commands appropriate for what you need to do - e.g docker images to see a list of available images. Have fun!