What is Docker?
Docker is the most common (and is also open-source) version of containerisation, i.e. a form of virtualisation where applications run in isolated containers while using a shared operating system (Linux in Docker’s case).
What are containers?
“A container is a standard unit of software that packages up code and all its dependencies so the application runs quickly and reliably from one computing environment to another” 1.
Hence, everything that is needed to run your project (e.g. python, R, packages…) is encapsulated and isolated into a container. This container is abstracted from the host operating system (OS) with only access to the binaries, libraries, configuration and dependencies that are built into such a container.
In a nutshell, it’s like having a lightweight virtual machine that includes everything needed to run an application: code, runtime, system tools, system libraries and settings.
Why should you use Docker?
Say goodbye to “but it works on my computer”, embrace the power of containerisation:
-
Holy grail of replicability:
- Can specify software versions (e.g. python 3.9 or even the OS)
- Will always run the same (and will be able to run) regardless of the infrastructure for instance, regardless of the OS. Therefore, it’s more replicable than using software environments such as via Conda
-
Increased portability and efficiency over VMs:
- Less overhead during startup and no need to set up a separate guest OS for each application.
- Containers take up less space than VMs, they have just the necessary.
-
Share your projects easily with your team:
- With Docker Hub it is very easy. In a way, it’s the equivalent of Github for Git but instead, for Docker.
Installing Docker
Windows Users
Download Docker from Docker’s official website, and follow the steps listed below to install and set up Docker on windows. In order to use the installation process below, you will need to have Windows Subsystem for Linux (WSL) of version 1.1.3.0 or later installed. Using WSL is advantageous because it will allow us to use both Linux and Windows.
See this building block for instructions on how to install and set up WSL.
Follow these steps:
- Click on Download Docker Desktop for Windows
- Double-click Docker Desktop Installer.exe to run the installer.
- If prompted, ensure the Use WSL 2 instead of Hyper-V option on the Configuration page is selected.
- Follow the instructions on the installation wizard to authorize the installer and proceed with the install.
- Once the installation is finished, the installer will ask you to restart. Accept the option to restart - Docker will open automatically once your computer restarts.
- When Docker opens, you will have to create a username and a password and verify your email to activate your Docker account.
- Docker will automatically integrate with your default WSL distribution. If you want to enable integration with additional distributions, open Docker, go to Settings > Resources > WSL integration, tick the option “Enable integration with additional distros” and click on “Apply & restart”.
If your admin account is different to your user account, you must add the user to the docker-users group. Run Computer Management as an administrator and navigate to Local Users and Groups > Groups > docker-users. Right-click to add the user to the group. Log out and log back in for the changes to take effect.
You can read more about installing Docker on Windows here.
Mac Users
Download Docker Desktop on Mac from Docker’s official website, where you will also find detailed instructions.
-
Double-click Docker.dmg to open the installer, then drag the Docker icon to the Applications folder.
-
Double-click Docker.app in the Applications folder to start Docker. In the example below, the Applications folder is in “grid” view mode.
-
The Docker menu displays the Docker Subscription Service Agreement window. Click the checkbox to indicate that you accept the updated terms and then click Accept to continue. Docker Desktop starts after you accept the terms.
Requirements
The requirements and recommendations are different depending on whether you have a Mac with an Intel chip or with Apple silicon:
-
Mac with Intel chip
WarningIn this case, macOS must be version 10.15 or newer, you must have at least 4GB of RAM and VirtualBox prior to version 4.3.30 must not be installed.
-
Mac with Apple silicon
TipTo get the best experience, it is recommended that you install Rosetta 2. To install Rosetta 2 manually from the command line, run the following command:
softwareupdate --install-rosetta
Linux Users
The Docker engine can be installed in different ways: setting up Docker’s repositories, manually by downloading the DEB package or using convenience scripts. Here we will go through the installation using the repository. If you prefer the other methods, find detailed instructions Docker’s install page
Installing using the repository
Set up the repository
- Update the
apt
package and install packages.
$ sudo apt-get update
$ sudo apt-get install \
ca-certificates \
curl \
gnupg \
lsb-release
- Add Docker’s official key
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
- Use the following command to set up the stable repository:
$ echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
Install the Docker Engine
Update the apt
package index and install the latest version of the Docker Engine:
$ sudo apt-get update
$ sudo apt-get install docker-ce docker-ce-cli containerd.io
Requirements
To install Docker Engine on Linux, you need the 64-bit version of one of these Ubuntu versions:
- Ubuntu Impish 21.10
- Ubuntu Hirsute 21.04
- Ubuntu Focal 20.04 (LTS)
- Ubuntu Bionic 18.04 (LTS)
Verify your Installation
Once installed, verify your installation works correctly by running the following on your terminal:
docker run hello-world
If everything is working correctly, you should get the following output:
-
Docker.com “What is a container” ↩︎