By Sajid Qureshi, Alibaba Cloud Community Blog author.
Rancher is an open-source Docker container management platform. It includes a Kubernetes distribution as well as the option to choose from Docker Swarm and Apache Mesos. You can run and manage Docker and Kubernetes containers very easily using Rancher. Rancher provides a huge library of applications which can be installed within a few clicks. It also includes modular infrastructure services including networking, load balancing, service discovery, monitoring and recovery.
You must have an Alibaba Cloud Elastic Compute Service (ECS) instance activated and have verified your valid payment method. If you are a new user, you can get a free account in your Alibaba Cloud account. If you don't know about how to set up your ECS instance, you can refer to this tutorial or quick-start guide. Your ECS instance must have at least 1GB RAM and 1 Core processor.
Follow the steps outlined below to learn how to install Rancher on an Alibaba Cloud ECS instance.
Before you install and run Rancher, you will need to install Docker first as it is required for Rancher. First of all, remove any old docker files using the following command.
sudo apt-get remove docker docker-engine docker.io
Next, update all the available packages. Run the
sudo apt-get update command and it will do the job for you. Then, install packages to allow
apt to use a repository over HTTPS using the following command:
sudo apt-get install \ apt-transport-https \ ca-certificates \ curl \ gnupg-agent \ software-properties-common
Add Docker's official GPG key using the following command:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
Now verify that you have the key
9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88 by searching for last 8 digits of the key's fingerprint. You can use the following command:
sudo apt-key fingerprint 0EBFCD88
You should see an output something similar to this:
pub rsa4096 2017-02-22 [SCEA] 9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88 uid [ unknown] Docker Release (CE deb) <firstname.lastname@example.org> sub rsa4096 2017-02-22 [S]
Now setup the stable repository using the following command:
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
Next, update the package list again using the
sudo apt-get update command, and list all the available versions of Docker in your repository using the following command.
apt-cache madison docker-ce
The output should be like this:
docker-ce | 17.09.1~ce-0~ubuntu | https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages docker-ce | 17.09.0~ce-0~ubuntu | https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages docker-ce | 17.06.2~ce-0~ubuntu | https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages docker-ce | 17.06.1~ce-0~ubuntu | https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages docker-ce | 17.06.0~ce-0~ubuntu | https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages docker-ce | 17.03.2~ce-0~ubuntu-xenial | https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages docker-ce | 17.03.1~ce-0~ubuntu-xenial | https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages docker-ce | 17.03.0~ce-0~ubuntu-xenial | https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages
Append the version-string, which is the second column, of the latest stable version after the
= in the following command to install the latest version of Docker CE. Now install a specific version of Docker of your choice using the following command.
sudo apt-get install docker-ce=17.09.1~ce-0~ubuntu
You can also install Docker without appending any version-string， but we recommend you to install a specific version of Docker for the production environment. Now verify that the Docker is installed correctly using the following command:
sudo docker run hello-world
This command downloads a test image and runs it in a container. When the container runs, it prints an informational message and exits. You should see the message similar to the following output.
Hello from Docker!
This message shows that your installation appears to be working correctly.
To generate this message, Docker took the following steps:
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:
For more examples and ideas, visit:
We have installed all the dependencies required and now we are ready to install and run Rancher. Run the following Docker command and it will do the job for you.
sudo docker run -d --restart=unless-stopped -p 8080:8080 rancher/server:stable
It takes less than a minute for the Rancher server to start up. Then open up your favorite web browser and visit port 8080 on your server
http://YourServerIP:8080. If nothing goes wrong, then you will see a Rancher user interface and it will guide you through adding your first cluster.
After the Rancher installed, you will need to configure access control. You can manage your users who have the permission to your Rancher server by configuring Rancher access control.
Move the cursor to the ADMIN menu on top of the web page and click on the Access Control. We want to use the local authentication method so, click on the LOCAL and then type your username and password. Finally, click on the Enable Local Auth button. You will be redirected to the Rancher dashboard with local authentication enabled.
Hosts are the most basic unit of resource within Rancher and are represented as any Linux server, virtual or physical. In order to add a new host to Rancher, you will need to create a new Alibaba Cloud ECS instance. Here we are using a new Alibaba Cloud ECS instance with Ubuntu operating system and having at least 2 GB RAM. First of all, set a new hostname to distinguish between these two servers. Run the following command and set a hostname of your choice.
sudo hostnamectl set-hostname host01
Now connect to the host server using ssh like this:
ssh sajid@IPAddress of host01
Next, install the latest Docker version using this script.
curl -fsSL https://get.docker.com -o get-docker.sh
Run this script using the
sh get-docker.sh command, and it will do the job for you. After the Docker is installed, you will need to start the docker services and enable it to launch at the boot time using the following commands.
systemctl start docker systemctl enable docker
Next, you will have to add rancher host01 to rancher server and to do so, open the Rancher dashboard and move your cursor to the
INFRASTRUCTURE menu and click on Hosts. On the next screen, click on the Add Host button and now you'll be asked for the Host Registration URL, here we will use default and click on the Save button.
On the next interface, select the host type. Rancher supports many host types such as Amazon EC2, Azure, DigitalOcean, and Exoscale host. For now, choose the custom host type, and enter the IP Address of rancher host01 server and copy the Docker command in the box.
Now go to rancher host01 terminal shell and paste the docker command like this:
sudo docker run -e CATTLE_AGENT_IP="192.168.33.11" --rm --privileged -v /var/run/docker.sock:/var/run/docker.sock -v /var/lib/rancher:/var/lib/rancher rancher/agent:v1.2.9 http://192.168.33.10:8080/v1/scripts/C7871D15E9CE6FFA892F:1514678400000:T9qDygb2pHroTMBuqA9Jylol8tU
The above command will download and create new container Rancher Agent on the rancher-host01 server. Finally, go back to Rancher dashboard host add page and click on the Close button.
In this tutorial, you learned to install Docker and Rancher on your Alibaba Cloud ECS instance installed with Ubuntu 16.04. You also configured Docker and Rancher on Alibaba Cloud ECS instance. Plus, you added a rancher host similarly. With it, you can deploy more hosts and you are ready to deploy other container and applications.
Alibaba Clouder - August 16, 2019
Alibaba Clouder - August 16, 2019
Alibaba Developer - December 9, 2020
Alibaba Developer - March 8, 2021
Alibaba Container Service - November 13, 2019
Alibaba Developer - March 3, 2020
An online computing service that offers elastic and secure virtual cloud servers to cater all your cloud hosting needs.Learn More
Alibaba Cloud Container Service for Kubernetes is a fully managed cloud container management service that supports native Kubernetes and integrates with other Alibaba Cloud products.Learn More
More Posts by Alibaba Clouder