In this tutorial, you’ll learn how to Install Rancher on CentOS 7 (single node/machine). Rancher is an open-source project that provides a container management platform built for organizations that deploy containers in production.
Steps to Install Rancher on CentOS 7 (Single node)
Prerequisite
- Access to a CentOS machine with root or sudo privileges
- Text editor
Step 1: Remove old docker package
Run below command which will remove old docker packages from CentOS
$ sudo yum remove docker docker-common docker-selinux docker-engine
As you can see in the above output there is no Docker installed earlier, so it will print “No match for argument: *” you can ignore it.
Sample Output:
[root@centos ~]# sudo yum remove docker docker-common docker-selinux docker-engine Loaded plugins: fastestmirror, langpacks No Match for argument: docker No Match for argument: docker-common No Match for argument: docker-selinux No Match for argument: docker-engine No Packages marked for removal [root@centos ~]#
Step 2: Install prerequisite packages on CentOS
$ sudo yum install -y yum-utils device-mapper-persistent-data lvm2
Sample Output:
[root@centos ~]# sudo yum install -y yum-utils device-mapper-persistent-data lvm2 Loaded plugins: fastestmirror, langpacks Loading mirror speeds from cached hostfile * base: mirrors.piconets.webwerks.in * epel: d2lzkl7pfhq30w.cloudfront.net * extras: mirrors.piconets.webwerks.in * rpmfusion-free-updates: mirrors.piconets.webwerks.in * updates: centos.mirror.snu.edu.in Resolving Dependencies --> Running transaction check ---> Package device-mapper-persistent-data.x86_64 0:0.8.5-1.el7 will be updated ---> Package device-mapper-persistent-data.x86_64 0:0.8.5-3.el7_9.2 will be an update ---> Package lvm2.x86_64 7:2.02.185-2.el7 will be updated ---> Package lvm2.x86_64 7:2.02.187-6.el7 will be an update --> Processing Dependency: lvm2-libs = 7:2.02.187-6.el7 for package: 7:lvm2-2.02.187-6.el7.x86_64 ---> Package yum-utils.noarch 0:1.1.31-52.el7 will be updated ---> Package yum-utils.noarch 0:1.1.31-54.el7_8 will be an update --> Running transaction check ---> Package lvm2-libs.x86_64 7:2.02.185-2.el7 will be updated ---> Package lvm2-libs.x86_64 7:2.02.187-6.el7 will be an update --> Processing Dependency: device-mapper-event = 7:1.02.170-6.el7 for package: 7:lvm2-libs-2.02.187-6.el7.x86_64 --> Running transaction check ---> Package device-mapper-event.x86_64 7:1.02.158-2.el7 will be updated ---> Package device-mapper-event.x86_64 7:1.02.170-6.el7 will be an update --> Processing Dependency: device-mapper-event-libs = 7:1.02.170-6.el7 for package: 7:device-mapper-event-1.02.170-6.el7.x86_64 --> Processing Dependency: device-mapper = 7:1.02.170-6.el7 for package: 7:device-mapper-event-1.02.170-6.el7.x86_64 --> Running transaction check ---> Package device-mapper.x86_64 7:1.02.158-2.el7 will be updated --> Processing Dependency: device-mapper = 7:1.02.158-2.el7 for package: 7:device-mapper-libs-1.02.158-2.el7.x86_64 ---> Package device-mapper.x86_64 7:1.02.170-6.el7 will be an update ---> Package device-mapper-event-libs.x86_64 7:1.02.158-2.el7 will be updated ---> Package device-mapper-event-libs.x86_64 7:1.02.170-6.el7 will be an update --> Running transaction check ---> Package device-mapper-libs.x86_64 7:1.02.158-2.el7 will be updated ---> Package device-mapper-libs.x86_64 7:1.02.170-6.el7 will be an update --> Finished Dependency Resolution Dependencies Resolved ======================================================================================== Package Arch Version Repository Size ======================================================================================== Updating: device-mapper-persistent-data x86_64 0.8.5-3.el7_9.2 updates 423 k lvm2 x86_64 7:2.02.187-6.el7 base 1.3 M yum-utils noarch 1.1.31-54.el7_8 base 122 k Updating for dependencies: device-mapper x86_64 7:1.02.170-6.el7 base 297 k device-mapper-event x86_64 7:1.02.170-6.el7 base 191 k device-mapper-event-libs x86_64 7:1.02.170-6.el7 base 191 k device-mapper-libs x86_64 7:1.02.170-6.el7 base 325 k lvm2-libs x86_64 7:2.02.187-6.el7 base 1.1 M Transaction Summary ======================================================================================== Upgrade 3 Packages (+5 Dependent packages) Total download size: 3.9 M Downloading packages: No Presto metadata available for base No Presto metadata available for updates (1/8): device-mapper-libs-1.02.170-6.el7.x86_64.rpm | 325 kB 00:00:10 (2/8): device-mapper-event-libs-1.02.170-6.el7.x86_64.rpm | 191 kB 00:00:10 (3/8): yum-utils-1.1.31-54.el7_8.noarch.rpm | 122 kB 00:00:02 (4/8): device-mapper-1.02.170-6.el7.x86_64.rpm | 297 kB 00:00:14 (5/8): device-mapper-persistent-data-0.8.5-3.el7_9.2.x86_64.rpm | 423 kB 00:00:08 (6/8): lvm2-2.02.187-6.el7.x86_64.rpm | 1.3 MB 00:00:12 (7/8): device-mapper-event-1.02.170-6.el7.x86_64.rpm | 191 kB 00:00:31 (8/8): lvm2-libs-2.02.187-6.el7.x86_64.rpm | 1.1 MB 00:04:20 ----------------------------------------------------------------------------------------------------- Total 15 kB/s | 3.9 MB 00:04:31 Running transaction check Running transaction test Transaction test succeeded Running transaction Updating : 7:device-mapper-1.02.170-6.el7.x86_64 1/16 Updating : 7:device-mapper-libs-1.02.170-6.el7.x86_64 2/16 Updating : 7:device-mapper-event-libs-1.02.170-6.el7.x86_64 3/16 Updating : 7:device-mapper-event-1.02.170-6.el7.x86_64 4/16 Updating : 7:lvm2-libs-2.02.187-6.el7.x86_64 5/16 Updating : device-mapper-persistent-data-0.8.5-3.el7_9.2.x86_64 6/16 Updating : 7:lvm2-2.02.187-6.el7.x86_64 7/16 Updating : yum-utils-1.1.31-54.el7_8.noarch 8/16 Cleanup : 7:lvm2-2.02.185-2.el7.x86_64 9/16 Cleanup : yum-utils-1.1.31-52.el7.noarch 10/16 Cleanup : 7:lvm2-libs-2.02.185-2.el7.x86_64 11/16 Cleanup : 7:device-mapper-event-1.02.158-2.el7.x86_64 12/16 Cleanup : 7:device-mapper-event-libs-1.02.158-2.el7.x86_64 13/16 Cleanup : 7:device-mapper-1.02.158-2.el7.x86_64 14/16 Cleanup : 7:device-mapper-libs-1.02.158-2.el7.x86_64 15/16 Cleanup : device-mapper-persistent-data-0.8.5-1.el7.x86_64 16/16 Verifying : 7:device-mapper-event-libs-1.02.170-6.el7.x86_64 1/16 Verifying : 7:lvm2-libs-2.02.187-6.el7.x86_64 2/16 Verifying : 7:device-mapper-libs-1.02.170-6.el7.x86_64 3/16 Verifying : 7:lvm2-2.02.187-6.el7.x86_64 4/16 Verifying : device-mapper-persistent-data-0.8.5-3.el7_9.2.x86_64 5/16 Verifying : 7:device-mapper-event-1.02.170-6.el7.x86_64 6/16 Verifying : 7:device-mapper-1.02.170-6.el7.x86_64 7/16 Verifying : yum-utils-1.1.31-54.el7_8.noarch 8/16 Verifying : 7:device-mapper-event-1.02.158-2.el7.x86_64 9/16 Verifying : device-mapper-persistent-data-0.8.5-1.el7.x86_64 10/16 Verifying : yum-utils-1.1.31-52.el7.noarch 11/16 Verifying : 7:device-mapper-event-libs-1.02.158-2.el7.x86_64 12/16 Verifying : 7:device-mapper-1.02.158-2.el7.x86_64 13/16 Verifying : 7:device-mapper-libs-1.02.158-2.el7.x86_64 14/16 Verifying : 7:lvm2-libs-2.02.185-2.el7.x86_64 15/16 Verifying : 7:lvm2-2.02.185-2.el7.x86_64 16/16 Updated: device-mapper-persistent-data.x86_64 0:0.8.5-3.el7_9.2 lvm2.x86_64 7:2.02.187-6.el7 yum-utils.noarch 0:1.1.31-54.el7_8 Dependency Updated: device-mapper.x86_64 7:1.02.170-6.el7 device-mapper-event.x86_64 7:1.02.170-6.el7 device-mapper-event-libs.x86_64 7:1.02.170-6.el7 device-mapper-libs.x86_64 7:1.02.170-6.el7 lvm2-libs.x86_64 7:2.02.187-6.el7 Complete! [root@centos ~]# [root@centos ~]# sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo Loaded plugins: fastestmirror, langpacks adding repo from: https://download.docker.com/linux/centos/docker-ce.repo grabbing file https://download.docker.com/linux/centos/docker-ce.repo to /etc/yum.repos.d/docker-ce.repo repo saved to /etc/yum.repos.d/docker-ce.repo [root@centos ~]#
Step 3: Add Docker yum repository
$ sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
Sample Output:
[root@centos ~]# sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo Loaded plugins: fastestmirror, langpacks adding repo from: https://download.docker.com/linux/centos/docker-ce.repo grabbing file https://download.docker.com/linux/centos/docker-ce.repo to /etc/yum.repos.d/docker-ce.repo repo saved to /etc/yum.repos.d/docker-ce.repo [root@centos ~]#
Step 4: Install Docker CE on CentOS
Run below command to install Docker CE latest stable version.
$ sudo yum install docker-ce
Sample Output:
[root@centos ~]# sudo yum install docker-ce Loaded plugins: fastestmirror, langpacks Loading mirror speeds from cached hostfile * base: centos.mirrors.estointernet.in * extras: mirrors.bkns.vn * updates: mirrors.inet.vn docker-ce-stable | 3.5 kB 00:00:00 (1/2): docker-ce-stable/7/x86_64/updateinfo | 55 B 00:00:00 (2/2): docker-ce-stable/7/x86_64/primary_db | 52 kB 00:00:00 Resolving Dependencies --> Running transaction check ---> Package docker-ce.x86_64 3:20.10.2-3.el7 will be installed --> Processing Dependency: container-selinux >= 2:2.74 for package: 3:docker-ce-20.10.2-3.el7.x86_64 --> Processing Dependency: containerd.io >= 1.4.1 for package: 3:docker-ce-20.10.2-3.el7.x86_64 --> Processing Dependency: docker-ce-cli for package: 3:docker-ce-20.10.2-3.el7.x86_64 --> Processing Dependency: docker-ce-rootless-extras for package: 3:docker-ce-20.10.2-3.el7.x86_64 --> Running transaction check ---> Package container-selinux.noarch 2:2.119.2-1.911c772.el7_8 will be installed ---> Package containerd.io.x86_64 0:1.4.3-3.1.el7 will be installed ---> Package docker-ce-cli.x86_64 1:20.10.2-3.el7 will be installed ---> Package docker-ce-rootless-extras.x86_64 0:20.10.2-3.el7 will be installed --> Processing Dependency: fuse-overlayfs >= 0.7 for package: docker-ce-rootless-extras-20.10.2-3.el7.x86_64 --> Processing Dependency: slirp4netns >= 0.4 for package: docker-ce-rootless-extras-20.10.2-3.el7.x86_64 --> Running transaction check ---> Package fuse-overlayfs.x86_64 0:0.7.2-6.el7_8 will be installed --> Processing Dependency: libfuse3.so.3(FUSE_3.2)(64bit) for package: fuse-overlayfs-0.7.2-6.el7_8.x86_64 --> Processing Dependency: libfuse3.so.3(FUSE_3.0)(64bit) for package: fuse-overlayfs-0.7.2-6.el7_8.x86_64 --> Processing Dependency: libfuse3.so.3()(64bit) for package: fuse-overlayfs-0.7.2-6.el7_8.x86_64 ---> Package slirp4netns.x86_64 0:0.4.3-4.el7_8 will be installed --> Running transaction check ---> Package fuse3-libs.x86_64 0:3.6.1-4.el7 will be installed --> Finished Dependency Resolution Dependencies Resolved ======================================================================================================================= Package Arch Version Repository Size ======================================================================================================================= Installing: docker-ce x86_64 3:20.10.2-3.el7 docker-ce-stable 27 M Installing for dependencies: container-selinux noarch 2:2.119.2-1.911c772.el7_8 extras 40 k containerd.io x86_64 1.4.3-3.1.el7 docker-ce-stable 33 M docker-ce-cli x86_64 1:20.10.2-3.el7 docker-ce-stable 33 M docker-ce-rootless-extras x86_64 20.10.2-3.el7 docker-ce-stable 9.0 M fuse-overlayfs x86_64 0.7.2-6.el7_8 extras 54 k fuse3-libs x86_64 3.6.1-4.el7 extras 82 k slirp4netns x86_64 0.4.3-4.el7_8 extras 81 k Transaction Summary ======================================================================================================================= Total download size: 102 M Installed size: 423 M Is this ok [y/d/N]: y Downloading packages: (1/8): container-selinux-2.119.2-1.911c772.el7_8.noarch.rpm | 40 kB 00:00:00 warning: /var/cache/yum/x86_64/7/docker-ce-stable/packages/docker-ce-20.10.2-3.el7.x86_64.rpm: Header V4 RSA/SHA512 Signature, key ID 621e9f35: NOKEYs | 38 MB 00:00:18 ETA Public key for docker-ce-20.10.2-3.el7.x86_64.rpm is not installed (2/8): docker-ce-20.10.2-3.el7.x86_64.rpm | 27 MB 00:00:17 (3/8): docker-ce-cli-20.10.2-3.el7.x86_64.rpm | 33 MB 00:00:11 (4/8): containerd.io-1.4.3-3.1.el7.x86_64.rpm | 33 MB 00:00:29 (5/8): fuse-overlayfs-0.7.2-6.el7_8.x86_64.rpm | 54 kB 00:00:00 (6/8): fuse3-libs-3.6.1-4.el7.x86_64.rpm | 82 kB 00:00:00 (7/8): slirp4netns-0.4.3-4.el7_8.x86_64.rpm | 81 kB 00:00:01 (8/8): docker-ce-rootless-extras-20.10.2-3.el7.x86_64.rpm | 9.0 MB 00:00:03 ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ Total 3.2 MB/s | 102 MB 00:00:32 Retrieving key from https://download.docker.com/linux/centos/gpg Importing GPG key 0x621E9F35: Userid : "Docker Release (CE rpm) <docker@docker.com>" Fingerprint: 060a 61c5 1b55 8a7f 742b 77aa c52f eb6b 621e 9f35 From : https://download.docker.com/linux/centos/gpg Is this ok [y/N]: y Running transaction check Running transaction test Transaction test succeeded Running transaction Installing : 2:container-selinux-2.119.2-1.911c772.el7_8.noarch 1/8 Installing : containerd.io-1.4.3-3.1.el7.x86_64 2/8 Installing : slirp4netns-0.4.3-4.el7_8.x86_64 3/8 Installing : 1:docker-ce-cli-20.10.2-3.el7.x86_64 4/8 Installing : fuse3-libs-3.6.1-4.el7.x86_64 5/8 Installing : fuse-overlayfs-0.7.2-6.el7_8.x86_64 6/8 Installing : 3:docker-ce-20.10.2-3.el7.x86_64 7/8 Installing : docker-ce-rootless-extras-20.10.2-3.el7.x86_64 8/8 Verifying : fuse3-libs-3.6.1-4.el7.x86_64 1/8 Verifying : 3:docker-ce-20.10.2-3.el7.x86_64 2/8 Verifying : fuse-overlayfs-0.7.2-6.el7_8.x86_64 3/8 Verifying : 1:docker-ce-cli-20.10.2-3.el7.x86_64 4/8 Verifying : slirp4netns-0.4.3-4.el7_8.x86_64 5/8 Verifying : 2:container-selinux-2.119.2-1.911c772.el7_8.noarch 6/8 Verifying : containerd.io-1.4.3-3.1.el7.x86_64 7/8 Verifying : docker-ce-rootless-extras-20.10.2-3.el7.x86_64 8/8 Installed: docker-ce.x86_64 3:20.10.2-3.el7 Dependency Installed: container-selinux.noarch 2:2.119.2-1.911c772.el7_8 containerd.io.x86_64 0:1.4.3-3.1.el7 docker-ce-cli.x86_64 1:20.10.2-3.el7 docker-ce-rootless-extras.x86_64 0:20.10.2-3.el7 fuse-overlayfs.x86_64 0:0.7.2-6.el7_8 fuse3-libs.x86_64 0:3.6.1-4.el7 slirp4netns.x86_64 0:0.4.3-4.el7_8 Complete! [root@centos ~]#
Step 5: Start the Docker Service
$ sudo systemctl start docker
Step 6: Enable docker service to auto-start on boot
$ sudo systemctl enable docker
Sample Output:
[root@centos ~]# sudo systemctl start docker [root@centos ~]# [root@centos ~]# sudo systemctl enable docker Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service. [root@centos ~]#
Step 7: Test Docker properly installed on CentOS
$ sudo docker run hello-world
Sample Output:
[root@centos ~]# sudo docker run hello-world Unable to find image 'hello-world:latest' locally latest: Pulling from library/hello-world 0e03bdcc26d7: Pull complete Digest: sha256:1a523af650137b8accdaed439c17d684df61ee4d74feac151b5b337bd29e7eec Status: Downloaded newer image for hello-world:latest 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. (amd64) 3. The Docker daemon created a new container from that image which 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. To try something more ambitious, you can run an Ubuntu container with: $ docker run -it ubuntu bash Share images, automate workflows, and more with a free Docker ID: https://hub.docker.com/ For more examples and ideas, visit: https://docs.docker.com/get-started/ [root@centos ~]#
Step 8: Install Rancher on CentOS 7
Run below command it will run Rancher container on port 8080.
$ sudo docker run -d --restart=unless-stopped -p 8080:8080 rancher/server:stable
Sample Output:
[root@centos ~]# sudo docker run -d --restart=unless-stopped -p 8080:8080 rancher/server:stable Unable to find image 'rancher/server:stable' locally stable: Pulling from rancher/server bae382666908: Pull complete 29ede3c02ff2: Pull complete da4e69f33106: Pull complete 8d43e5f5d27f: Pull complete b0de1abb17d6: Pull complete 422f47db4517: Pull complete 79d37de643ce: Pull complete 69d13e08a4fe: Pull complete 2ddfd3c6a2b7: Pull complete bc433fed3823: Pull complete b82e188df556: Pull complete dae2802428a4: Pull complete 07bf18e8eec0: Pull complete 339e24088f91: Pull complete 9372455de0b8: Pull complete 5a33b348bf45: Pull complete 3286997d8874: Pull complete bd79bfb954de: Pull complete ba7c19991a31: Pull complete 0c19aca4f8a1: Pull complete e03fc76c8997: Pull complete Digest: sha256:95b55603122c28baea4e8d94663aa34ad770bbc624a9ed6ef986fb3ea5224d91 Status: Downloaded newer image for rancher/server:stable 39175040d0511e2b124d94ab7fd5d399ca250fab1dd2334c9637d9baf11f87bd [root@centos ~]#
Wait till the container is in running state, you can check it with below command.
$ docker ps
Sample Output:
[root@centos ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 39175040d051 rancher/server:stable "/usr/bin/entry /usr…" 7 minutes ago Up 7 minutes 3306/tcp, 0.0.0.0:8080->8080/tcp exciting_panini [root@centos ~]# [root@centos ~]#
Access your Rancher UI on a Web Browser
http://server-ip:8080 replace “server-ip” with your actual server’s IP address
this is the end of the article → How to Install Rancher on CentOS 7.
See also:
Supported version of Docker.