01 Set Up

Here I will guide you where to find how to install Docker. Docker is most important piece of software you need. The second one, arguably is Git, but don’t worry I’ve included Git inside docker image, this means, that you will get it “for free” as soon as you install Docker. Using Git is not strictly necessary, it just for saving your time and prevent typing errors.

I will not give you precise step-by-step tutorial how to install Docker, because this tutorial will be obsolete when you will read this book. Instead I will give you key search world that you will be able to find one in you favorite search engine.

General notes:

  1. You should have working Internet access.
  2. If you see some exception just search for exact same phrase in Internet. In almost all cases, you’re not first person who get it, and you will find what should you do or at least in what direction make your research for solution. Of course, you should understand the actions that you’re doing, because you can make damage to your computer.
  3. The code of this chapter is freely available on GitHub. Search for “git-hub alex-ber” and than open repository with name IntroCS:

Click on IntroCS link and than click on 01_setup directory. You will find commands specifies in this chapter one by name. After each command you will see in {name_of_the_file in 01_setup directory}.

The official site of Docker is good starting point. Just type “docker download” to find him. Now, you should chose different path, according the OS that you’re using. It is also possible to install in AWS, Google Cloud, Microsoft Azure, Oracle Cloud or another cloud provider. I will talk about option to install in AWS at the end.

There is a gotcha, though. Official docker site push Docker Desktop on you. It is ok to install Docker Desktop, because you’re going to use it in education purpose, but for our purposes it is overkill.

For Windows user use “docker download Windows” in the search. You should find something like https://docs.docker.com/desktop/install/windows-install/. Note, that Docker Desktop is what you’re going to install.

Here you can chose what technology you want to use “behind the scene” — WSL 2 backend or Hyper-V backend. I have experience only with Hyper-V backend, but it was very challenging to install it (and it is not considered production-ready).

  • For Hyper-V backend I had to install Windows Subsystem for Linux (WSL) (it wasn’t installed) and to turn on in BIOS-level hardware virtualization, so called Hypervisor (Hyper-V).
  • For WSL 2 backend you will need install the Linux kernel update package.

Also, I have found the official guide very difficult to follow, so I have used multiple how-tos named “How to install Docker on Windows”.

If you’re scared, this was intentional. :-) If you have no problem with changing BIOS settings and navigate through multiple tutorial, go ahead and install Docker Desktop on Windows. If not I can propose you the following alternatives:

  • To search for “How To Install Docker Without Docker Desktop On Windows”. There are also many how-tos. Personally, I didn’t try them. But you should now some Linux (usually Ubuntu). The instructions also are very fragile. Quote:

Please note this does not work with “Ubuntu 22.04 LTS” distribution at this time. It works with the following distributions:

Ubuntu 18.04 LTS

Ubuntu 20.04 LTS

Ubuntu 20.04.4 LTS

https://medium.com/geekculture/run-docker-in-windows-10-11-wsl-without-docker-desktop-a2a7eb90556d

  • Find a friend, some IT-enthusiast, that can install Docker Desktop for you.
  • Change the OS you’re using for another one, that is more friendly to the Docker ecosystem (that what I did)
  • Use AWS install, go to the end of the chapter.

[See also appendix 1 for using Docker without sudo and appendix 2 for sanity test].

For macOS users it is actually very simple. If you have homebrew installed, you can execute the following command to install Docker:

brew cask install docker

{01_macos_docker_install}

If you don’t have homebrew, just type:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"

{02_macos_homebrew_install}

or search in the internet.

My college installed Docker on macOS just typing one command above.

IMPORTANT: To force the docker to use linux/amd64 platform by default on macOS (and not ARM/v7), run the following command:

export DOCKER_DEFAULT_PLATFORM=linux/amd64

{03_macos_default_platform}

You can put it in your .zshrc file for Mac M1 or any appropriate alternative.

[See also appendix 1 for using Docker without sudo and appendix 2 for sanity test].

For Linux it is a bit more lines of code, but fairly straight-forward. I did it on Ubuntu 20.04 LTS. Quote:

Install Docker

You can use your operating system’s package manager to install the latest Docker release. You’ll need to add Docker’s repository, update your package lists and then install Docker.

Debian/Ubuntu

Begin by adding dependencies needed by the installation process:

sudo apt-get update
sudo apt-get install apt-transport-https ca-certificates curl gnupg lsb-release

{04_debian_docker_install1}

Next, add Docker’s repository GPG key:

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg

{05_debian_docker_install2}

Add the repository to your sources and update your package lists:

echo "deb [arch=amd64 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
sudo apt-get update

{06_debian_docker_install3}

Now you can install Docker:

sudo apt-get install docker-ce docker-ce-cli containerd.io

{07_debian_docker_install4}

[See also appendix 1 for using Docker without sudo and appendix 2 for sanity test].

Fedora

Add Docker’s package repository:

sudo dnf -y install dnf-plugins-core
sudo dnf config-manager --add-repo https://download.docker.com/linux/fedora/docker-ce.repo

{08_fedora_install1}

[See also appendix 1 for using Docker without sudo and appendix 2 for sanity test].

Install Docker:

sudo dnf install docker-ce docker-ce-cli containerd.io

{09_fedora_install2}

[See also appendix 1 for using Docker without sudo and appendix 2 for sanity test].

CentOS

Add Docker’s package repository:

sudo yum -y install yum-utils
sudo yum-config-manager --add-repo https://download.docker.com/linux/fedora/docker-ce.repo

{10_centos_install1}

Install Docker:

sudo yum install docker-ce docker-ce-cli containerd.io

{11_centos_install2}

https://www.howtogeek.com/devops/how-to-install-docker-and-docker-compose-on-linux/

Amazon Linux 2

Login into remote AWS server using the ssh command:

ssh ec2-user@ec2-ip-address-dns-name-here

{12_amazon_linux21}

[Probably, you will need to pass key here, something with -i to the .pem file of EC2]

Install docker, run:

sudo yum install docker

{13_amazon_linux22}

https://www.cyberciti.biz/faq/how-to-install-docker-on-amazon-linux-2/

[Note: Adding your user to secondary docker group decrease a bit security of your system. If somebody will get to your system under your user, he can use docker to effectively do anything he want. On another hands, using this command enable PyCharm Professional interact with Docker seamlessly.

sudo usermod -a -G docker ec2-user

{14_amazon_linux23}

id ec2-user

{15_amazon_linux24}

# Reload a Linux user's group assignments to docker w/o logout
newgrp docker

{16_amazon_linux25}

[Note: Adding your user to secondary docker group decrease a bit security of your system. If somebody will get to your system under your user, he can use docker to effectively do anything he want. On another hands, using this command enable PyCharm Professional interact with Docker seamlessly.

See also appendix 1 for using Docker without sudo and appendix 2 for sanity test].

Last, but not least, AWS approach. Search for “How to Create an AWS Account”. You will need your credit card. AWS offer a free tier, it even offers free tier, but I should warn you that pricing system is anything but transparent.

Note: If you do chose the free tier option, chose t2.micro instance type. If for some reason you’re don’t want to use a free tier t2.micro instance type will not be available for you. In that case I recommend to use a1.medium instance type. I’ve created special kind of docker image for ARM/v8 that can be run on A1 instance type. A1 instance type built on AWS Graviton Processor that belong to ARM/v8 family that has about half cost of t* contra-part that runs on AMD64.

Next, search for “How to Use Docker Containers with AWS EC2”. If you install Amazon Linux, you can look on Ubuntu section above.

Your hosting OS will be EC2. You can install whatever version of Linux you want, provided it has some terminal and you know how to SSH into it (don’t worry this is usually part of the tutorial).

It may be challenging, so you can call somebody to assist you.

IMPORTANT: You should pay attention to the instance type of EC2 you’re choosing. It is totally fine, to have 1 vCPU

See also appendix 1 for using Docker without sudo and appendix 2 for sanity test.

Appendix:

1. Using Docker Without Sudo

The Docker daemon runs as root. You must usually prefix Docker commands with sudo. This can get tedious if you’re using Docker often. Adding yourself to the docker group will let you use Docker without sudo.

sudo usermod -aG docker $USER

{17_docker_without_sudo}

Once you’re in the group, logout and login again. Alternatively, run the newgrp docker command to immediately login to the updated group. You should now be able to drop sudo from Docker commands.

https://www.howtogeek.com/devops/how-to-install-docker-and-docker-compose-on-linux/

Note: Adding your user to secondary docker group decrease a bit security of your system. If somebody will get to your system under your user, he can use docker to effectively do anything he want. On another hands, using this command enable PyCharm Professional interact with Docker seamlessly.

2. Sanity Test

How to test that Docker was installed correctly?

  1. First, try
docker --version

{18_sanity1}

You should see the version. If you see some error, the most common reason is that the Docker Engine daemon is down.

You can check whether Docker’s running by inspecting its service with systemctl. There are two components to consider, docker and containerd.

sudo systemctl status docker.service
sudo systemctl status containerd.service

{19_sanity2}

docker is the Docker Engine daemon which the CLI sends commands to. containerd is the underlying runtime which actually runs your containers.

If one of them just start them:

sudo systemctl start docker.service
sudo systemctl start containerd.service

{20_sanity3}

2. Try

docker run hello-world:latest

{21_sanity4}

This what all how-tos says to do. You should see “Hello from Docker!” message.

This story is part of my new book.

--

--

Senior Software Engineer at Pursway

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store