Getting started with Docker: Installation, first steps

By: (plus.google.com) +David Herron; Date: April 5, 2018

Tags: Docker »»»» Docker MAMP

Let's start this journey into Docker by learning how to install it on popular systems. Installation is a lot simpler today than at the beginning, especially on Mac and Windows. You youngsters don't know how easy you have it now that Docker for Mac and Docker for Windows exist. In the old days we had to walk 10 miles through the snow, uphill both ways, to install VirtualBox along with a specialized virtual machine to use Docker.

macOS installation

Official instructions: (docs.docker.com) https://docs.docker.com/docker-for-mac/install/

Simple - you download the Docker for Mac bundle, which is named Docker.dmg. As the name implies this is a disk image, which you double-click to open. Once opened, you drag the Docker icon to the Applications folder.

Once copied to the Applications folder, you double click the Docker icon to launch the application.

It starts like a regular Mac application, and in all ways behaves like one.

An icon is added to the top status bar. The icon shows current status, and gives access to a menu showing further details, and allowing you to start Kitematic and perform some other diagnostic rituals.

Docker for Mac relies on an extremely light-weight hypervisor, HyperKit. Inside that hypervisor is running a Linux system with enough capability to host Docker services. Processes associated with your Docker containers are not running in macOS, but instead are running in this Linux image inside the hypervisor.

Mac hardware must be a 2010 or newer model. The OS must be macOS El Capitan 10.11 or newer. If VirtualBox is installed, it must be newer than version 4.3.30.

Windows installation

Official instructions: (docs.docker.com) https://docs.docker.com/docker-for-windows/install/

Once you've downloaded the installer, Docker for Windows Installer.exe, run it to go through the install wizard.

Once Docker is installed, it is launched through the Start menu, just like any Windows application. From here it behaves like a Windows app, for example an icon is added to the taskbar.

Docker for Windows relies on an extremely light-weight hypervisor, Hyper-V. Hunt around Windows and you'll find some applications for inspecting Hyper-V based VM's, one of which will be your Docker VM. Like for Docker for Mac, the Docker containers you run on Windows will not be Windows processes, but instead will run in the Linux image running inside the Hyper-V hypervisor.

Virtualization must be enabled which may mean a trip to your BIOS or UEFI or whatever it is you use to configure the hardware before booting the computer.

Linux installation

Official Ubuntu instructions: (docs.docker.com) https://docs.docker.com/install/linux/docker-ce/ubuntu/

Official Debian instructions: (docs.docker.com) https://docs.docker.com/install/linux/docker-ce/debian/

Official CentOS instructions: (docs.docker.com) https://docs.docker.com/install/linux/docker-ce/centos/

Official Fedora instructions: (docs.docker.com) https://docs.docker.com/install/linux/docker-ce/fedora/

Docker runs natively on Linux and therefore does not require a hypervisor. Installation is done through the official package management system for the above distros. On other distros you have a couple hoops to jump.

You may need to remove old versions first:

$ sudo apt-get remove docker docker-engine docker.io

Then:

$ sudo apt-get update
$ sudo apt-get install \
    apt-transport-https \
    ca-certificates \
    curl \
    software-properties-common
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
$ sudo apt-key fingerprint 0EBFCD88
$ sudo add-apt-repository \
   "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
   $(lsb_release -cs) \
   stable"
$ sudo apt-get update
$ sudo apt-get install docker-ce

Details are on the official instructions page. That may look like a lot of steps, but it's fairly straight-forward. The first few lines add the Docker repository to your sources, and the last one installs Docker CE.

Post-install instruction for Linux

All versions of Linux have some post-install steps to make it more convenient to use Docker.

See: (docs.docker.com) https://docs.docker.com/install/linux/linux-postinstall/

$ sudo groupadd docker
$ sudo usermod -aG docker $USER

This adds a new group named docker. Any user in the docker group can run the Docker commands, meaning they do not have to use sudo docker but just docker. Repeat the usermod command for each user ID that is to have access to the docker command.

# for systemctl
$ sudo systemctl enable docker
# for upstart
$ echo manual | sudo tee /etc/init/docker.override
# for chkconfig
$ sudo chkconfig docker on

The next step is configuring Docker to launch when the system reboots. That means any restart: always Docker container can be used as a background daemon service.

Those are the most important things to do. You can also configure storage drivers and many other settings.

Tire Kicking

david@nuc2:~$ docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
ca4f61b1923c: Pull complete 
Digest: sha256:97ce6fa4b6cdc0790cda65fe7290b74cfebd9fa0c9b8c38e979330d547d22ce1
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://cloud.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/engine/userguide/

The hello-world container is used as a demonstration of some basic Docker usage. This demonstrates how Docker automatically downloads any container image it doesn't have locally, and then the image is instantiated into a Container before execution.

By default the docker run command runs the container in the foreground, meaning that the standard-output of the launched command prints on the users terminal.

In this case it's a simple command to print a useful message describing some further steps you can take with Docker.

david@nuc2:~$ docker ps -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                     PORTS                                                                NAMES
b94b72b0bbab        hello-world         "/hello"                 3 minutes ago       Exited (0) 3 minutes ago                                                                        priceless_kilby
c2c9253b571b        nextcloud           "/entrypoint.sh apac…"   24 hours ago        Up 24 hours                80/tcp                                                               nextcloud
7bf3ee9bddd9        nginx_nginx         "sh -c 'nginx && cro…"   25 hours ago        Up 25 hours                0.0.0.0:80->80/tcp, 0.0.0.0:443->443/tcp                             nginx
0152a5a7dc46        gogs/gogs           "/app/gogs/docker/st…"   4 days ago          Up 4 days                  22/tcp, 0.0.0.0:3080->3080/tcp, 3000/tcp, 0.0.0.0:10022->10022/tcp   gogs

This shows the Docker containers running on the system. I have a few executing full-time on this server. The hello-world container is listed here with the name priceless_kilby.

If a Docker container is executed without specifying a name, Docker will concoct a name. In this case priceless_kilby was what was chosen.

david@nuc2:~$ docker rm priceless_kilby
priceless_kilby

Didn't your mother teach you to clean up after yourself? Mine did. Not that I paid attention, but she did teach me this. Eventually I listened.