How to Install Docker on Fedora 28 / Fedora 27
Docker is an open source container virtualization technology that has gained immense popularity in recent times, and it offers a more efficient way to deploy an application. With Docker, the application resides inside the container on top of the base OS (Linux operating system).
Docker uses the Kernel features such as cgroups and namespace to allow the independent container to run on single os instance.
Docker is now coming in two editions,
- Community Edition (CE)
- Enterprise Edition (EE)
Log in as root or switch to the root user.
sudo su -
Remove old versions:
Remove the package named “docker” or “docker-engine” along with its dependencies. If your machine does not have a Docker package, then skip the below step.
dnf remove -y docker docker-common container-selinux docker-selinux docker-engine
Important contents such as images, volumes, and networks under /var/lib/docker/ are preserved.
The Docker community package is now called “docker-ce“. Let’s add the Docker CE repository on your machine.
dnf -y install curl curl -o /etc/yum.repos.d/docker-ce.repo https://download.docker.com/linux/fedora/docker-ce.repo
Now, install the latest version of Docker community edition using dnf command.
dnf -y install docker-ce
Eg: dnf -y install docker-ce-17.03.1.ce-1.fc28
Working with Docker
Now, you have Docker installed on your machine. Start the Docker service in case if it is not started automatically after the installation
systemctl start docker systemctl enable docker
Run your first Docker container
# docker run -it fedora echo Hello-World
When you run a “docker run” command, docker starts a container with Fedora base image. By default, Docker checks locally for base images; if it is not found, it will start downloading the base image from Docker Registry or Docker private registry.
Since we are running this Fedora container for the first time, the output will look like below.
Unable to find image 'fedora:latest' locally latest: Pulling from library/fedora a8ee583972c2: Pull complete Digest: sha256:25f7dac76b2c88d8b7e0b1d6213d3406e77c7f230bfa1e66bd1cbb81a944eaaf Status: Downloaded newer image for fedora:latest Hello-World
Once the image has been downloaded, Docker will start the container and echo the command “Hello-World” in the console.
Managing Docker as a non-root user
As you can see in my command, I had to run docker commands as the root user. To avoid this, you can follow below instruction to allow non-root users to run Docker containers.
Create a group called “docker“, run the following commands with root privileges.
# groupadd docker
Add a user that is to be a part of docker group, replace “raj” with your own username.
# useradd raj
Add a user to docker group.
# usermod -aG docker raj
Change the permission.
# chown root:docker /var/run/docker.sock
Logout and login back.
Now, you should be able to run the Docker engine with a non-root user.
Here are some interesting tutorials for you to get started: