Docker Introduction

by

In this post I'm going to give you an introduction for using Docker.
But first, let's talk about the underlying technology.

What's a container

A container is a type of virtualization tool but unlike a Virtual Machine, a container shares its Kernel with its host, and allows access to resources using cgroups rather than fully virtualizing them the way a hypervisor does. Containers are complementary to VMs, and can be used with or without them.

Two types of containers

There are two types of containerization methods:

  • Operating System Container
    • Virtualizes an entire operating system, such as Ubuntu or Centos.
      This is the heavier solution, popularized by LXC/LXD and often used with Alpine Linux because of its lightweight nature. Such a container acts like a normal VM albeit much more lightweight, and can be administered the same way you administer an operating system.
  • Application Container
    • A newer, more popular method of using a container popularized by Docker where only the components needed to run the application running on the container are present. This gives you a more secure, more lightweight solution.

Installing Docker

If you don't mind using an older version of Docker, you can always install it from your software repository. Note that you may be missing newer features we may use in This tutorial.

Installing via Software Repositories

On Ubuntu 20.04:

sudo apt install docker docker-compose

Installing the Latest Version

Ubuntu 20.04

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu focal stable"sudo apt install docker-ce docker-composesudo usermod -aG docker $USER

Log out and in for the last line's changes to take effect

What about Centos and Docker?

So with the case of Centos, the current version of docker is not supported and causes a dependency nightmare. I could give you instructions to maybe circumvent this and install the dependencies you need manually or try to go around the problem with the --nobest flag but instead I will give you another alternative.

Podman

Podman is a daemonless, open source, Linux native tool designed to make it easy to find, run, build, share and deploy applications using Open Containers Initiative (OCI) Containers and Container Images. Podman provides a command line interface (CLI) familiar to anyone who has used the Docker Container Engine. Most users can simply alias Docker to Podman (alias docker=podman) without any problems. Similar to other common Container Engines (Docker, CRI-O, containerd), Podman relies on an OCI compliant Container Runtime (runc, crun, runv, etc) to interface with the operating system and create the running containers. This makes the running containers created by Podman nearly indistinguishable from those created by any other common container engine.

http://docs.podman.io/en/latest/

Podman is in the Centos Software repositories, and provides a podman-compose command that is compatible with docker compose which we'll use later in the tutorial. It should be almost completely compatible with Docker but it features additional features such as pod management as well as being daemonless, which solves some important security issues with Docker.

sudo dnf install podman podman-composealias docker-compose="podman-compose"

You should now be able to run docker and docker-compose commands.

Testing our installation

Let's pull and run a simple container

docker run hello-world

If all is well you should get the following output:

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 bashShare images, automate workflows, and more with a free Docker ID: https://hub.docker.com/For more examples and ideas, visit: https://docs.docker.com/get-started/

I'll see you next time for some handy Docker/Podman commands!