In the second part of our Docker tutorial series, we’ll go through the necessary steps to installing Docker CE (Community Edition) on CentOS 7/ RHEL 7 and Ubuntu 18.04 LTS / Ubuntu 16.04 LTS.
Prerequisites
Before proceeding with this tutorial, you to need a user with sudo
privileges to follow the Docker CE installation steps.
Install Docker CE On CentOS 7/ RHEL 7
Before you install Docker CE, we have to install some required packages, although, you need to set up the Docker repository.
1. The device-mapper-persistent-data
and lvm2
are required by the devicemapper
storage driver. So, use the below command to install the required packages.
$ yum install -y yum-utils device-mapper-persistent-data lvm2
2. Use the following command to set up the stable repository.
$ sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
3. Now that the Docker repository is enabled, install the latest version of Docker CE by running:
$ sudo yum install docker-ce
4. Once the Docker package is installed, start and enable Docker daemon at system boot:
$ sudo systemctl start docker $ sudo systemctl enable docker
5. Finaly, verify that Docker CE is installed correctly by running the below command:
$ docker -v Docker version 18.09.6, build 481bc77156
Install Docker CE On Ubuntu 16 / Ubuntu 18
1. Update the apt
package index:
$ sudo apt-get update
2. Install packages to allow apt
to use a repository over HTTPS:
$ sudo apt-get install \ apt-transport-https \ ca-certificates \ curl \ gnupg-agent \ software-properties-common
3. Add Docker’s official GPG key:
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
4. Now, install the latest version of Docker CE by executing the following commands:
$ sudo apt-get update $ sudo apt-get install docker-ce
5. Once the Docker package is installed, start and enable Docker daemon at system boot:
$ sudo systemctl start docker $ sudo systemctl enable docker
6. Finaly, verify that Docker CE is installed correctly by running the below command:
$ docker -v Docker version 18.09.6, build 481bc77156
Executing the Docker Command Without Sudo
By default, to manage Docker you need an administrator privileges. So, if you want to run Docker commands as a non-root user without sudo
, you need to add your user to the docker group which is created during the installation of the Docker CE package. Run the bellow command to do that:
$ sudo usermod -aG docker $USER
So, to verify that Docker CE is installed correctly and that you can run docker commands without sudo
, run the below command to run the hello-world
image.
$ docker run hello-world Unable to find image 'hello-world:latest' locally latest: Pulling from library/hello-world 9bb5a5d4561a: Pull complete Digest: sha256:f5233545e43561214ca4891fd1157e1c3c563316ed8e237750d59bde73361e77 Status: Downloaded newer image for hello-world:latest Hello from Docker! This message shows that your installation appears to be working correctly.
To view all the containers, execute the following command:
docker container ls -a CONTAINER ID IMAGE COMMAND CREATED STATUS e3d0079ed8bd hello-world "/hello" About a minute ago Exited (0) About a minute ago
Conclusion
You have learned how to install Docker CE on your CentOS 7 / RHEL 7 and Ubuntu 18.04 LTS/ Ubuntu 16.04 LTS machine.