Day - 89 of DevOps

Day - 89 of DevOps

Installing Docker on Ubuntu

Docker is the modern platform for high-velocity innovation a tool that is used to automate the deployment of applications in lightweight containers so that applications can work efficiently in different environments.

A few quick notes about docker installation on ubuntu

  • Multiple containers run on the same hardware

  • Maintains isolated applications

  • Enables high productivity

  • Quick and easy to configure

The following steps work for Ubuntu and similar distributions. First, make sure you’ve got all the prerequisite packages for the installation process:

Prerequisites

In order to install docker Ubuntu, you will need to meet the following requirements:

  • OS: Linux Ubuntu

  • Memory: 512MB RAM (2GB Recommended)

  • A sufficient amount of disk and CPU (Dependant on the applications )

  • It only works on a 64-bit Linux installation.

  • It requires Linux kernel version 3.10 or higher.

i) Check the current kernel version

$ uname -r

ii) Check the current Ubuntu version

$ lsb_release -a

iii) Check if ubuntu is running on 32-bit or 64-bit

$ uname -a

OS requirements

To set up Docker Engine, you'll need to use the 64-bit version of one of these Ubuntu versions:

  • Ubuntu Noble 24.04 (LTS)

  • Ubuntu Mantic 23.10 (EOL: July 12, 2024)

  • Ubuntu Jammy 22.04 (LTS)

  • Ubuntu Focal 20.04 (LTS)

Docker Engine for Ubuntu is compatible with x86_64 (or amd64), armhf, arm64, s390x, and ppc64le (ppc64el) architectures.

$ sudo apt-get update
$ sudo apt-get install -y ca-certificates curl gnupg lsb-release

Next, download and save the GPG key used to sign the Docker repositories:

$ sudo mkdir -p /etc/apt/keyrings
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg

This allows the apt package manager to verify the authenticity of Docker’s packages. Now add the repository to your package lists:

$ echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
  $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

The command automatically selects the correct repository for your operating system version and processor architecture.

Update your package lists to include the new repository:

$ sudo apt-get update

Finally, install the docker-ce, docker-ce-cli, and containered packages:

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

They have the following roles:

  • docker-ce – The Docker daemon that manages your containers.

  • docker-ce-cli – The CLI you use to interact with the daemon.

  • containerd.ioContainered is a container runtime; it wraps operating system features such as cgroups to start and run your containers, on request from the Docker daemon.

Complete the installation by adding yourself to the docker group. This allows you to run docker CLI commands without using sudo. Logout and back in again to apply this change.

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

Checking Docker Is Working

Once you’ve installed Docker, you can check it’s working by starting a basic container. The hello-world image on Docker Hub is a good choice.

Run the following command to start a container with the image:

$ docker run hello-world:latest

You should see output similar to the following:

Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
2db29710123e: Pull complete 
Digest: sha256:c77be1d3a47d0caf71a82dd893ee61ce01f32fc758031a6ec4cf1389248bb833
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.

The first few lines show the Docker daemon recognizing that you’ve never used the hello-world image before, so it has to download it from Docker Hub. It then starts the container and streams its output to your terminal. All the lines from “Hello from Docker” onwards are emitted by the process inside the container.

Your Docker installation is ready to use.

Install using the convenience script

Docker provides a convenience script at get.docker.com to install Docker into development environments non-interactively. The convenience script isn't recommended for production environments, but it's useful for creating a provisioning script tailored to your needs.

$ curl -fsSL https://get.docker.com -o get-docker.sh
$ sudo sh ./get-docker.sh --dry-run
  • The script requires root or sudo privileges to run.

  • The script attempts to detect your Linux distribution and version and configure your package management system for you.

  • The script doesn't allow you to customize most installation parameters.

  • The script installs dependencies and recommendations without asking for confirmation. This may install a large number of packages, depending on the current configuration of your host machine.

  • By default, the script installs the latest stable release of Docker, containerd, and runc. When using this script to provision a machine, this may result in unexpected major version upgrades of Docker. Always test upgrades in a test environment before deploying to your production systems.

  • The script isn't designed to upgrade an existing Docker installation. When using the script to update an existing installation, dependencies may not be updated to the expected version, resulting in outdated versions.