Docker is one of the most popular tools for deploying software in containers. This free tool helps you to make your application portable and run it on any platform without installing any dependencies. It is a relatively new platform and is constantly updated by a large developer community. With Docker, you can run multiple containers on the same hardware. Docker is an alternate solution for virtual machines that are lightweight and more resource-friendly.

In this post, we will explain how to install and use Docker and Docker Compose on Fedora.

Step 1 – Add Docker Repo

By default, the Docker and Docker Compose packages are not included in the Fedora default repo, so you will need to add a Docker repo to the Yum repository. You can add it with the following command.

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

The above command will create a docker-ce.repo file in the Yum configuration directory.

Step 2 – Install Docker and Docker Compose

Now, run the following command to install Docker, Docker Compose, and other packages to Fedora.

dnf install docker-ce docker-ce-cli containerd.io docker-compose-plugin docker-compose -y

After the successful installation, start and enable the Docker service using the following command.

systemctl start docker
systemctl enable docker

You can now verify the Docker version using the following command.

docker --version

Output:

Docker version 20.10.17, build 100c701

To check the Docker service status, run the following command.

systemctl status docker

Output:

● docker.service - Docker Application Container Engine
     Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled; vendor preset: disabled)
     Active: active (running) since Sat 2023-05-20 03:54:38 EDT; 8min ago
TriggeredBy: ● docker.socket
       Docs: https://docs.docker.com
   Main PID: 5219 (dockerd)
      Tasks: 13
     Memory: 41.4M
        CPU: 1min 31.505s
     CGroup: /system.slice/docker.service
             └─5219 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock

If you want to see more information about Docker, run the following command.

docker info

Output:

Client:
 Context:    default
 Debug Mode: false
 Plugins:
  app: Docker App (Docker Inc., v0.9.1-beta3)
  buildx: Docker Buildx (Docker Inc., v0.8.2-docker)
  compose: Docker Compose (Docker Inc., v2.6.0)
  scan: Docker Scan (Docker Inc., v0.17.0)

Server:
 Containers: 0
  Running: 0
  Paused: 0
  Stopped: 0
 Images: 0
 Server Version: 20.10.17
 Storage Driver: overlay2
  Backing Filesystem: xfs
  Supports d_type: true
  Native Overlay Diff: true
  userxattr: false
 Logging Driver: json-file
 Cgroup Driver: systemd
 Cgroup Version: 2
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
 Swarm: inactive
 Runtimes: io.containerd.runc.v2 io.containerd.runtime.v1.linux runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 10c12954828e7c7c9b6e0ea9b0c02b01407d3ae1
 runc version: v1.1.2-0-ga916309
 init version: de40ad0
 Security Options:

Step 3 – Verify Docker

After installing Docker, you will need to verify Docker. Let’s download and run the hello-world container.

docker run hello-world

This will pull the hello-world Docker image from the Docker Hub repository and create a container for it.

Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
719385e32844: Pull complete 
Digest: sha256:fc6cf906cbfa013e80938cdf0bb199fbdbb86d6e3e013783e5a766f50f5dbce0
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

Output.

REPOSITORY    TAG       IMAGE ID       CREATED       SIZE
hello-world   latest    9c7a54a9a43c   2 weeks ago   13.3kB

To check the status of the hello-world container, run the following command.

docker ps -a

Output.

CONTAINER ID   IMAGE         COMMAND    CREATED              STATUS                          PORTS     NAMES
2f37b19f050d   hello-world   "/hello"   About a minute ago   Exited (0) About a minute ago             flamboyant_lovelace

Step 4 – How to Use Docker

Docker allows you to pull and run any operating system inside the container.

Let’s pull the Fedora image and create a container using the following command.

docker run -dit fedora:latest

You will see the following output.

Unable to find image 'fedora:latest' locally
latest: Pulling from library/fedora
86c577c44422: Pull complete 
Digest: sha256:88b02539d545dcc81f1a991b06fd2a6e7c550f4192ed3625843926b56522a37c
Status: Downloaded newer image for fedora:latest
a2a919fc421cce733984fc8ed69259bcab045e50c14cbc185cd4e38efe72bcd5

You can verify the running container using the following command.

docker ps

Output:

CONTAINER ID   IMAGE           COMMAND       CREATED          STATUS         PORTS     NAMES
a2a919fc421c   fedora:latest   "/bin/bash"   10 seconds ago   Up 9 seconds             beautiful_euler

To connect the running container, run the following command.

docker exec -it a2a919fc421c /bin/bash

You will get into the Fedora container as shown below.

[root@a2a919fc421c /]#

Now, verify the Fedora version using the following command.

cat /etc/os-release 

Output:

NAME="Fedora Linux"
VERSION="38 (Container Image)"
ID=fedora
VERSION_ID=38
VERSION_CODENAME=""
PLATFORM_ID="platform:f38"
PRETTY_NAME="Fedora Linux 38 (Container Image)"
ANSI_COLOR="0;38;2;60;110;180"
LOGO=fedora-logo-icon
CPE_NAME="cpe:/o:fedoraproject:fedora:38"
DEFAULT_HOSTNAME="fedora"
HOME_URL="https://fedoraproject.org/"
DOCUMENTATION_URL="https://docs.fedoraproject.org/en-US/fedora/f38/system-administrators-guide/"
SUPPORT_URL="https://ask.fedoraproject.org/"
BUG_REPORT_URL="https://bugzilla.redhat.com/"
REDHAT_BUGZILLA_PRODUCT="Fedora"
REDHAT_BUGZILLA_PRODUCT_VERSION=38
REDHAT_SUPPORT_PRODUCT="Fedora"
REDHAT_SUPPORT_PRODUCT_VERSION=38
SUPPORT_END=2024-05-14
VARIANT="Container Image"
VARIANT_ID=container

Finally, exit from the Fedora container using the following command.

[root@a2a919fc421c /]# exit

Step 5 – Remove Docker and Docker Compose

You can remove the Docker, Docker Compose, and other packages using the following command.

dnf remove docker-ce docker-ce-cli containerd.io docker-compose-plugin docker-compose -y

Now, clean all package caches using the following command.

dnf clean all

Conclusion

In this post, we explained how to install Docker and Docker Compose on Fedora. We also show you how to use Docker to run any container. You can now try to install Docker and Docker Compose on dedicated server hosting from Atlantic.Net!