How to Install Docker CE on CentOS 7

1
33
How to Install Docker CE on CentOS 7

What is Docker?

Docker is a tool designed to make it easier to create, deploy, and run applications by using containers. Containers allow a developer to package up an application with all of the parts it needs, such as libraries and other dependencies, and ship it all out as one package. By doing so, thanks to the container, the developer can rest assured that the application will run on any other Linux machine regardless of any customized settings that machine might have that could differ from the machine used for writing and testing the code.

In a way, Docker is a bit like a virtual machine. But unlike a virtual machine, rather than creating a whole virtual operating system, Docker allows applications to use the same Linux kernel as the system that they’re running on and only requires applications to be shipped with things not already running on the host computer. This gives a significant performance boost and reduces the size of the application.

And importantly, Docker is open-source. This means that anyone can contribute to Docker and extend it to meet their own needs if they need additional features that aren’t available out of the box.

Also Read: How to Setup Apache Virtual Hosts on Ubuntu 18.04 and 16.04

Who is Docker for?

Now the second question that you might ask is who are the intended users Docker? So answer it in easy words it targets both developers and system administrators, and it is widely used as a part of DevOps (developers + operations).

Using Docker it makes the life of a developer a lot easier and he can focus more on the code rather than worrying about the system that the code will be deployed and ultimately running. All the dependencies will be handled by the Docker container.

How to Install Docker CE on CentOS 7

Step 1: System update

First, let’s make sure we’re running on a clean system. Update all packages.

yum update

Then, install the Docker CE dependencies.

yum install -y yum-utils device-mapper-persistent-data lvm2

Step 2: Installing Docker CE

Docker provides a repository where you can fetch the stable Docker CE version. Install it with this command:

yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo

To install Docker, simply run:

yum install -y docker-ce

Optional: In case you want to use the latest version of Docker CE, you have to enable those repositories which are disabled by default:

yum-config-manager --enable docker-ce-edge
yum-config-manager --enable docker-ce-test

Once the Docker package is installed, start the Docker daemon and enable it to automatically start at boot time:

sudo systemctl start dockersudo systemctl enable docker

To verify that the Docker service is running type:

sudo systemctl status docker

This will show output like docker.service is active and running if you get any error then follow the above steps after removing the old version of docker from your system.

You can also run the following command to verify that docker is successfully installed:

docker -v

Also read: 15 Best Linux Applications that You MUST HAVE in 2019

Step 3: Allow Docker commands without sudo

Launching a container requires administrator privileges. If you don’t want to run Docker as the root user, you can run it from your account using sudo. Adding “sudo” in front of each Docker command is tedious – to avoid this, add your user to the “docker” group:

usermod -aG docker your_username

Now, start the Docker service:

systemctl start docker

Step 4: Test Docker

You can use the handy “hello-world” test to verify whether or not Docker will run on your system.

    docker run hello-world

Upon success, this will return the welcome message:

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.
3. The Docker daemon created a new container from that image that 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.

You can also run an Ubuntu container with:

    docker run -it ubuntu bash

Let’s enable Docker to run when your system boots.

    systemctl enable docker

Congratulations! You have now installed Docker CE on CentOS 7.

SHARE
Previous articleHow to Setup and Install PassionFruit On macOS
I am a Linux enthusiast still learning more about Linux and get my way around. I love writing articles and share what I know and Learn new things. I am also a security researcher and penetration tester.