Installing Docker On CentOS 7 / RHEL 7
Docker is a container virtualization technology that has gained widespread popularity in recent times; it offers a more efficient way to deploy the application. With Docker, the applications reside inside the container on top of the Linux operating system. Docker uses Kernel features such as cgroups and namespace to allow an independent container to run on single os instance.
Install from Docker (Official):
Docker is now available in two editions,
Community Edition (CE)
Enterprise Edition (EE)
Here, we will install Docker Comunity Edition (CE).
Uninstall older versions of Dockers, named “docker” or “docker-engine” along with associated dependencies.
# yum -y remove docker-common docker container-selinux docker-selinux docker-engine
Do not worry about the contents inside /var/lib/docker/, all will be preserved.
The Docker Comunity package is now called “docker-ce“. Let’s add the CE repository for docker installation.
# yum -y install wget
# wget https://download.docker.com/linux/centos/docker-ce.repo -O /etc/yum.repos.d/docker-ce.repo
Install the latest version of Docker CE using the following command.
# yum -y install docker-ce
# yum -y install docker
Working with Docker:
Now you have Docker installed onto your machine, start the Docker service in case if it is not started automatically after the installation
# systemctl start docker.service
# systemctl enable docker.service
Step 1 | Remove Old Versions
$ sudo yum remove docker docker-common docker-selinux docker-engine
Step 2 | Install Required Packages
$ sudo yum install -y yum-utils device-mapper-persistent-data lvm2
Step 3 | Setup the Docker CE Repository
$ sudo yum-config-manager –add-repo https://download.docker.com/linux/centos/docker-ce.repo
Step 4 | Update the Packages
$ sudo yum update
Step 5 |Install specific version (Production recommended)
$ sudo yum list docker-ce.x86_64 –showduplicates | sort -r
Loaded plugins: amazon-id, rhui-lb, search-disabled-repos
docker-ce.x86_64 17.06.0.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.03.2.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.03.1.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.03.0.ce-1.el7.centos docker-ce-stable
Available Packages
$ sudo yum install docker-ce-
Step 6 | Install through respository
$ sudo yum install docker-ce
Step 7 | Start Docker
$ sudo systemctl start docker
Step 8 | Verify the Installation
$ sudo docker run hello-world
Change default Image and Container location in Docker
What to do if you have existing containers and images?
If you want the existing containers and images to be migrated to the new location, don’t reload the service daemon and start the docker service, right after modifying docker.conf, move the existing data in /var/lib/docker to the new location. And create a symlink.
Note: I have not tried the following since there was no need for me to keep existing containers and images. But these steps should work; If you are facing any trouble or aware of any alternative method please comment. I will then modify the post. Please take a backup before venturing further.
# cp –rp /var/lib/docker /mnt/new_volume
# ln -s /mnt/new_volume /var/lib/docker
After this reload daemon and start docker service,
# sudo systemctl daemon-reload
# sudo systemctl start docker
Recent Comments