Install Docker on CentOS
Installing Docker on CentOS is fairly straightforward and only takes a few commands. So let’s go through it step by step.
1. Remove Docker
Section titled “1. Remove Docker”Before we start, we need to remove any Docker dependencies. If you’ve never installed Docker, don’t worry. You can skip this step.
$ sudo yum remove docker \ docker-client \ docker-client-latest \ docker-common \ docker-latest \ docker-latest-logrotate \ docker-logrotate \ docker-engine2. Set up the repository
Section titled “2. Set up the repository”We need to install the yum-utils package. yum-utils gives us the yum-config-manager that we need to set up the repository.
$ sudo yum install -y yum-utils
$ sudo yum-config-manager \ --add-repo \ https://download.docker.com/linux/centos/docker-ce.repo3. Install Docker
Section titled “3. Install Docker”With yum-utils installed, we can go ahead and install Docker.
$ sudo yum install docker-ce docker-ce-cli containerd.io4. Test its working
Section titled “4. Test its working”Now everything is installed, we should test if it’s working. So start Docker.
$ sudo systemctl start dockerNow, start a container to check that Docker is installed correctly.
$ sudo docker run hello-world5. Add non-root users
Section titled “5. Add non-root users”You’ll notice that if you want to start Docker as a non-root user, you’ll probably run into this error.
Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get http://%2Fvar%2Frun%2Fdocker.sock/v1.40/containers/json: dial unix /var/run/docker.sock: connect: permission deniedDon’t worry. There’s an easy fix for that. First, let’s create the Docker group.
$ sudo groupadd dockerThen add the non-root user to the group.
$ sudo usermod -aG docker $USERWith all that done, you’ve got Docker set up and ready to use.