How to install Docker on Fedora Linux system

Docker is a tool that is used to run software in a container. It’s a great way for developers and users to worry less about compatibility with an operating system and dependencies because the contained software should run identically on any system.

Docker is available for download and installation on Fedora as well as most other distributions of Linux. However, installing it on Fedora can be a bit tricky because Red Hat doesn’t offer native support for Docker on its distributions. Instead, Red Hat pushes support for Podman, an alternative to Docker. This makes Docker a bit harder to install, but it’s still possible on Fedora.

In this guide, we’ll show you how to install Docker on Fedora and get started with installing containerized software. After Docker is installed, you can use it to install software packages much the same way you would use your distro’s package manager to download an app. The difference of using Docker is that everything is more automated, with compatibility and dependencies no longer being potential issues.

In this tutorial you will learn:

  • How to install Docker
  • How to start Docker and make it run automatically at boot
  • How to run Docker without root
  • How to search for a Docker image
  • How to install a Docker image
  • How to run a Docker image
  • How to monitor Docker with various commands
  • How to automatically start a Docker container

Docker running a container image on Fedora Linux

Docker running a container image on Fedora Linux

Software Requirements and Linux Command Line Conventions
Category Requirements, Conventions or Software Version Used
System Fedora Linux
Software Docker
Other Privileged access to your Linux system as root or via the sudo command.
Conventions # – requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
$ – requires given linux commands to be executed as a regular non-privileged user

Install Docker on Fedora

 



Red Hat has put a few obstacles in our way, so we can’t just install Docker with a simple dnf install command. We’ll need to add the Docker repository to our system first, and then uninstall a few conflicting packages that are installed by default on Fedora.

  1. Start by installing the dnf-plugins-core package, in case it’s not already on your system. This will allow you to manage your dnf repositories and add the official Docker repo to them.
    $ sudo dnf -y install dnf-plugins-core
    
  2. Next, add the Docker repository to your system with the following command.
    $ sudo dnf config-manager --add-repo https://download.docker.com/linux/fedora/docker-ce.repo
    
  3. Before we begin installing Docker, we need to remove the podman and buildah packages from our system, as they conflict with Docker and will inhibit it from being installed.
    $ sudo dnf remove podman buildah
    
  4. Finally, we can install the three Docker packages we’ll need by executing the following command.
    $ sudo dnf install docker-ce docker-ce-cli containerd.io
    
  5. Once installation is completed, start the Docker service and, optionally, enable it to run whenever the system is rebooted:
    $ sudo systemctl start docker.service
    $ sudo systemctl start containerd.service
    $ sudo systemctl enable docker.service
    $ sudo systemctl enable containerd.service
    
  6. You can verify that Docker is installed and gather some information about the current version by entering this command:
    $ sudo docker version
    
  7.  



    Output of docker version command

    Output of docker version command

  8. There is also a quick and easy way to see how many Docker containers are currently running and see some of Docker’s configured options by entering:
    $ sudo docker info
    
  9. Output of docker info command showing its configuration

    Output of docker info command showing its configuration

Run Docker without root

By default, you’ll have to use sudo or login to root anytime you want to run a Docker command. This next step is optional, but if you’d prefer the ability to run Docker as your current user, add your account to the docker group with this command:

$ sudo usermod -aG docker $USER

You’ll need to reboot your system for those changes to take effect.

$ reboot

Searching for a Docker image

 



Now you’re ready to install images with Docker. If you already know the name of an image that you’d like to install, you can move on to the next section. If you need to search through Docker for the desired software, you can use the following command syntax:

$ docker search [name]

For example, let’s try searching for nginx, which is popular web server software.

$ docker search nginx
Docker can search for any available container images

Docker can search for any available container images

As you can see, there is one official image for nginx (indicated by the OFFICIAL column) simply called nginx. There are also other releases available, and you would have to read their descriptions to see what they do differently from the official image.

Install a Docker image

Once you know which image you’d like to install, you can use the following command to instruct Docker to download the desired software. Just as an example, we’ll install the hello-world package which can be used to make sure that Docker is able to download and run images successfully.

$ docker pull hello-world

 



Docker downloading a container image

Docker downloading a container image

The output in the screenshot above indicates that Docker was able to find and download the image we specified.

Running a Docker image

Now that the image is downloaded, run it with the following command:

$ docker run hello-world
Docker was able to run the hello-world image successfully

Docker was able to run the hello-world image successfully

Monitoring Docker

Docker gives us a lot of options to see what’s going on with our images, how many system resources they’re using, etc. The following commands come in handy for monitoring Docker and our installed images.

To see which Docker containers are running and check their current status, type:

$ docker container ls
The docker container ls command shows currently running containers

The docker container ls command shows currently running containers

To see a list of all the Docker images installed, type:

$ docker images

 



The docker images command shows which images are currently installed in Docker

The docker images command shows which images are currently installed in Docker

To see the current CPU, RAM, and network usage of running images, type:

$ docker stats
See the current system usage of Docker images with docker stats command

See the current system usage of Docker images with docker stats command

To see Docker’s network configuration, type:

$ docker network ls
See currently configured networks in Docker with docker network ls

See currently configured networks in Docker with docker network ls

Automatically start a container

We’ve arleady seen how to make sure the Docker service start automatically when your computer boots up. In case you skipped that step, here’s the command again.

$ sudo systemctl enable docker.service
$ sudo systemctl enable containerd.service

 



We can also control Docker services to make them start automatically. Here are a few commands to control their behavior. We’ll use nginx as our example software in these commands.

  1. To start a new container and configure it to automatically restart unless it’s been stopped or Docker has restarted, execute the following command.
    $ docker run -d --restart unless-stopped nginx
    
  2. If the container is already running, use this command to make sure it restarts automatically.
    $ docker update --restart unless-stopped nginx
    
  3. We can also make sure that all containers are restarted automatically, unless explicitly stopped, by using the following command.
    $ docker update --restart unless-stopped $(docker ps -q)
    
  4. To always restart a container, even if it’s been manually stopped, use the always option instead of unless stopped.
    $ docker update --restart always nginx
    
  5. You can also use the on-failure option to only allow containers to restart automatically if they’ve encountered an error.
    $ docker update --restart on-failure nginx
    
  6. Lastly, to configure your container back to the default setting, which means no automatic restarting, use the no option.
    $ docker update --restart no nginx
    

 



Troubleshooting

If you are encountering issues with Docker, including permission errors or “Cannot connect to the Docker daemon”, the Docker developers have a handy script that you can run to check for a bunch of common issues. Here’s how to download and run it.

$ curl https://raw.githubusercontent.com/docker/docker/master/contrib/check-config.sh > check-config.sh
$ bash ./check-config.sh
Running the Docker check-config script shows us if anything is misconfigured on our system

Running the Docker check-config script shows us if anything is misconfigured on our system

Closing Thoughts

Although RHEL, and by extension Fedora, doesn’t support Docker natively, it’s still possible to get it up and running, as we’ve seen in this guide. RHEL native tools like podman and buildah are compatible with Docker but don’t need a server/client architecture to run. Using native tools, where possible, is always the recommended way to go, but for one reason or another you may still want to install the original Docker.