How To Install Docker on Linux

Docker’s popularity has increased rapidly over the past years, and it has evolved traditional software development. Docker’s containers allow for the immense economy of scale and have made development scalable, while at the same time keeping the process user-friendly. Our Docker tutorial will help you understand Docker containers, and its benefits, and will also help learn the ways to build docker environment and docker commands. So start learning now to know everything about docker – from its advantages to how it is different from other virtual machines, know how to install it and master several docker technologies.

Red Hat Enterprise Linux (RHEL) and CentOS

Docker runs on RHEL 7 and CentOS 7.

Install Docker

Install with Yum

  1. Log into your system as a user with sudo privileges.
  2. Update your system: sudo yum update -y.
  3. Add the yum repo (use the code below for both RHEL 7 and CentOS 7):
     $ sudo tee /etc/yum.repos.d/docker.repo <<-'EOF'
     [dockerrepo]
     name=Docker Repository
     baseurl=https://yum.dockerproject.org/repo/main/centos/7/
     enabled=1
     gpgcheck=1
     gpgkey=https://yum.dockerproject.org/gpg
     EOF
    
  4. Install Docker:
     sudo yum install docker-engine -y
    
  5. Start Docker:
     sudo service docker start
    
  6. Verify Docker:
     sudo docker run hello-world
    

Install with the Docker Installation Script

  1. Log into your system as a user with sudo privileges.
  2. Update your system:
     sudo yum update -y
    
  3. Run Docker’s installation script:
     curl -fsSL https://get.docker.com | sh;
     This script adds the docker.repo repository and installs Docker.
  4. Start Docker:
     sudo service docker start
    
  5. Verify Docker:
     sudo docker run hello-world
    

The Docker Group

If you prefer, you can set up a docker group to run Docker (instead of root). However, as docker must have sudo access, docker receives the same access as root.

  1. Run the following command to create a Docker group and add your user to the group (replace USERNAME with your username):
     sudo groupadd docker && sudo usermod -aG docker USERNAME
    
  2. Log out and back in.
  3. Verify Docker works without sudo:
     docker run hello-world
    

Start Docker at Boot

Run one of the following:

  • sudo chkconfig docker on
  • sudo systemctl enable docker

How To Install Docker on Ubuntu

Steps for Installing Docker:

1. Open the terminal on Ubuntu.

2. Remove any Docker files that are running in the system, using the following command:

$ sudo apt-get remove docker docker-engine docker.io

After entering the above command, you will need to enter the password of the root and press enter.

3. Check if the system is up-to-date using the following command:

$ sudo apt-get update

4. Install Docker using the following command:

$ sudo apt install docker.io

You’ll then get a prompt asking you to choose between y/n – choose y

5. Install all the dependency packages using the following command:

$ sudo snap install docker

6. Before testing Docker, check the version installed using the following command:

$ docker --version

7. Pull an image from the Docker hub using the following command:

$ sudo docker run hello-world

Here, hello-world is the docker image present on the Docker hub.

8. Check if the docker image has been pulled and is present in your system using the following command:

$ sudo docker images

9. To display all the containers pulled, use the following command:

$ sudo docker ps -a

10. To check for containers in a running state, use the following command:

$ sudo docker ps

You’ve just successfully installed Docker on Ubuntu!

Reference

https://docs.docker.com/engine/install/

https://www.simplilearn.com/tutorials/docker-tutorial

https://runnable.com/docker/install-docker-on-linux

What is Docker?

Print Friendly, PDF & Email
%d bloggers like this: