Becoming a Docker
Getting Linux servers up and running, easy as pie. Follow Nathan Taylor’s guide!
Over the past two months in this column we’ve been looking at the Windows Subsystem for Linux (WSL), a tool that allows you to run Linux server apps on Windows without the hassle of setting up an entire virtual machine to do so. That makes it possible to enjoy the host of Linux-exclusive server apps, including staples like ownCloud (for creating a private cloud) and Rocket.chat (for creating private chat networks), without needing to run a separate or virtual Linux machine.
Unfortunately, WSL is not without its limitations. Adding apps that aren’t included in the base Ubuntu repository can be a massive pain. Which is where Docker comes in, a tool that allows a much simpler install process – it makes the process of installing Linux servers easy.
Understanding Docker
So what does Docker do? Docker is kind of like virtualisation lite, using the host’s kernel but virtualising the application.
For a lot of people, of course, that’s probably not a very useful explanation. So let’s talk about what it does in practice: it lets you download a single “package” (known as a container) that has everything you need to run a particular application. Want to run ownCloud? Download an ownCloud Docker container that has everything you need built in. You don’t need to worry about installing and configuring Apache, MySQL, SSL, PHP and all the other little things that you need to worry about normally. It’s all included in the container.
That makes it vastly easier to install and run complex apps with many dependencies, especially on Linux and WSL.
Getting started
For this issue, we’re going to talk about using Docker on Windows with WSL. Before going ahead with this, we highly recommend going back through our last two issues, where we discussed installing the Windows Subsystem for Linux. The short version of that process is:
Go into Windows Features and enable Windows Subsystem for Linux as well as Virtual Machine Platform (which is required for WSL 2). You can just type ‘turn windows features’ in the search bar to take you to the ‘Turn Windows features on or off’ control panel to find it.
Go to the Microsoft Store and find and download Ubuntu, which will install the server version of Ubuntu on top of WSL. Then run it.
Installing Docker
One of the most useful things about Docker is that it actually has inbuilt WSL support. You can download and install Docker for Windows, and it will talk to your WSL Kernel in the back end for running Linux apps. From a user perspective, it just looks like you’re installing Linux apps on Windows – and they actually work.
But it does take a little initial setup, largely to get WSL version 2 running. To start, you need to be running version 2004 or higher of Windows 10. It’s a feature update that may not have been installed automatically, but you can install it by going to Settings > Update & Security. This new version includes some very important updates to WSL, including the much improved version 2 that Docker requires.
Now we need to update the Linux Kernel. Go to:
https://docs.microsoft.com/ en-gb/windows/wsl/wsl2-kernel
Download and run the updater to get the latest WSL2 Linux kernel. That should bring you up to date.
Finally, you also need to make sure you’re using WSL 2. Open up a Windows command line (type cmd into the search bar) and then in the Windows command line, type these lines:
wsl --set-default-version 2 wsl --set-version Ubuntu 2
Now, at last, to install Docker.
Head to docker.com and find and download Docker Desktop for Windows. Run it. It will detect that you have WSL installed, and ask if it should enable integration (you should).
Docker should have added an icon to the task bar. Click on the icon and open the Dashboard (on first run, the Dashboard will appear automatically).
Now to check some settings. Click on the Settings icon. In General, the Use the WSL 2 based engine should be checked. Now go to Resources > WSL integration. Enable it for the Linux distribution you’re using (Ubuntu, if you’ve been following our guides). Now we’re all set to get going.
Using Docker
Now that Docker is installed, we can start downloading pre-made containers, which are far and away the easiest way to get servers up and running in Linux.
It should be noted that Docker still uses a command line interface on Windows. As long as Docker is running (shown by the icon in the taskbar), you can issue Docker commands in the Windows command line interface (either cmd or PowerShell). The Dashboard is mostly used to see what is running and to start and stop installed containers.
To use it is actually fairly simple, however. Open a Windows command prompt and type: docker run switches imagename Where switches are the specific command options for that particular container image, and the imagename is the name of the container (usually the name of the main app).
If you head to hub.docker.com,
there are thousands of container images available, including official images for most of the major apps. Find the app you want on that site, and note the name of the image. Most apps have specific instructions, and will provide you with the command line you need to download, install and start the container.
Let’s take a look at an example: Nextcloud, a cloud file sharing and collaboration platform. Nextcloud has an official Docker image, which can viewed at hub.docker. com/_/nextcloud/. There are instructions for installing it on the page. You don’t need to download anything here: just go to a Windows command prompt and type:
docker run -d -p 8080:80 nextcloud
You will get a note that you haven’t installed Nextcloud yet, but Docker will then automatically download and run the container for you.
The container image contains everything needed to run Nextcloud, including Apache, SSL and much more. As long as it’s running, you have Nextcloud; and data is persistent between sessions, so you can close it and restart it again without losing data.
And that’s it! Nextcloud is installed and running, and you’ll see it on the Dashboard as a running container. You can start, stop and delete it, open it in a web browser, and launch a command line just by clicking the buttons next to it.
Then, all you have to do to access Nextcloud’s admin interface is open up a web browser and go to: http://localhost:8080/
There are literally thousands upon thousands of Linux apps that you can now launch and use in Windows. Have a browse through the Docker Hub collection: you’re sure to find many things you’d like to try out!