Atlantic.Net Blog

How to Install and Use Docker on Arch Linux

Docker is an open-source software platform used to build, test, and deploy applications quickly. It is a lightweight containerization platform that packages up an application and all its dependencies and delivers them into the virtual container. You can then run this container in any Linux operating system. Docker uses resource isolation that allows you to run multiple containers on the same operating system. Docker was originally designed to run on the Linux platform. Now, it also runs on Microsoft Windows and Apple OS X.

This post will show you how to install and use Docker on Arch Linux.

Step 1 – Configure Repository

By default, the default repository is outdated in Arch Linux, so you will need to modify the default mirror list. You can do it by editing the mirrorlist configuration file:

nano  /etc/pacman.d/mirrorlist

Remove all lines and add the following lines:

## Score: 0.7, United States
Server = http://mirror.us.leaseweb.net/archlinux/$repo/os/$arch
## Score: 0.8, United States
Server = http://lug.mtu.edu/archlinux/$repo/os/$arch
Server = http://mirror.nl.leaseweb.net/archlinux/$repo/os/$arch
## Score: 0.9, United Kingdom
Server = http://mirror.bytemark.co.uk/archlinux/$repo/os/$arch
## Score: 1.5, United Kingdom
Server = http://mirrors.manchester.m247.com/arch-linux/$repo/os/$arch
Server = http://archlinux.dcc.fc.up.pt/$repo/os/$arch
## Score: 6.6, United States
Server = http://mirror.cs.pitt.edu/archlinux/$repo/os/$arch
## Score: 6.7, United States
Server = http://mirrors.acm.wpi.edu/archlinux/$repo/os/$arch
## Score: 6.8, United States
Server = http://ftp.osuosl.org/pub/archlinux/$repo/os/$arch
## Score: 7.1, India
Server = http://mirror.cse.iitk.ac.in/archlinux/$repo/os/$arch
## Score: 10.1, United States
Server = http://mirrors.xmission.com/archlinux/$repo/os/$arch

Save and close the file, then update all the package indexes with the following command:

pacman -Syu

Step 2 – Install Docker

By default, the Docker package is available in the Arch Linux default repository. You can install it easily using the following command.

pacman -S docker

Once the Docker is installed, enable the Docker service to start at system reboot.

systemctl enable docker

Next, restart your system to apply the system.

reboot

After the successful restart, you can verify the status of Docker using the following command.

systemctl status docker

You will get the following output.

● docker.service - Docker Application Container Engine
     Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; preset: disabled)
     Active: active (running) since Thu 2023-01-05 00:00:42 EST; 56s ago
TriggeredBy: ● docker.socket
       Docs: https://docs.docker.com
   Main PID: 265 (dockerd)
      Tasks: 15 (limit: 2349)
     Memory: 138.7M
        CPU: 486ms
     CGroup: /system.slice/docker.service
             ├─265 /usr/bin/dockerd -H fd://
             └─356 containerd --config /var/run/docker/containerd/containerd.toml --log-level info

You can check Docker information using the following command.

docker info

You should see the following output.

Client:
 Context:    default
 Debug Mode: false

Server:
 Containers: 0
  Running: 0
  Paused: 0
  Stopped: 0
 Images: 0
 Server Version: 20.10.22
 Storage Driver: overlay2

Step 3 – Verify Docker Installation

Next, download and run a simple hello-world container to test whether the Docker works or not.

docker run hello-world

This will download the hello-world docker image and run it as shown below.

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

For more examples and ideas, visit:
 https://docs.docker.com/get-started/

You can verify the downloaded image using the following command.

docker images

You should see the following output.

REPOSITORY    TAG       IMAGE ID       CREATED         SIZE
hello-world   latest    feb5d9fea6a5   15 months ago   13.3kB

You can also check the status of the hello-world container using the following command.

docker ps -a

You will get the following output.

CONTAINER ID   IMAGE         COMMAND    CREATED          STATUS                      PORTS     NAMES
0afb4631a34b   hello-world   "/hello"   18 seconds ago   Exited (0) 17 seconds ago             epic_kalam

Step 4 – How to Use Docker

With Docker, you can download any image and run it inside the container.

Let’s download the Ubuntu image and run it inside the container.

docker run -dit ubuntu:latest

You will get the following output.

Unable to find image 'ubuntu:latest' locally
latest: Pulling from library/ubuntu
6e3729cf69e0: Pull complete 
Digest: sha256:27cb6e6ccef575a4698b66f5de06c7ecd61589132d5a91d098f7f3f9285415a9
Status: Downloaded newer image for ubuntu:latest
40c92b4107f8d7ff37d41d61a5c9b13b87ace2f8e14a32be8c5c52cc35daa6c9

You can verify the status of the Ubuntu container using the following command.

docker ps

You should see the following output.

CONTAINER ID   IMAGE           COMMAND   CREATED          STATUS          PORTS     NAMES
40c92b4107f8   ubuntu:latest   "bash"    10 seconds ago   Up 10 seconds             tender_wozniak

Next, connect to the Ubuntu container using the following command.

docker exec -it 40c92b4107f8 /bin/bash

You will get into the following shell.

root@40c92b4107f8:/# 

Now, verify your container operating system version using the following command.

cat /etc/lsb-release

You should see the following output.

DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=22.04
DISTRIB_CODENAME=jammy
DISTRIB_DESCRIPTION="Ubuntu 22.04.1 LTS"

Finally, exit from the container using the following command.

root@40c92b4107f8:/# exit

Conclusion

In this post, we explained how to install Docker on Arch Linux. We also showed you how to download and run a container using Docker. You can now try to deploy Docker on dedicated hosting from Atlantic.Net!

Get a $250 Credit and Access to Our Free Tier!

Free Tier includes:
G3.2GB Cloud VPS a Free to Use for One Year
50 GB of Block Storage Free to Use for One Year
50 GB of Snapshots Free to Use for One Year