One of the hottest technologies today is Docker and the ability to manage Linux Containers. As with most new things it is important to be able to setup and play with it, just to see what all the excitement is about. Follow along as we install a fully functioning Docker system on a CenturyLink Cloud server.
In order to create a CenturyLink Cloud server we need to use the web interface, or the "control panel". This can be found at control.tier3.com. You will need to have an account and associated user name in order to login. From the pull down menu select "create server" and follow the dialogs to select the datacenter, number of CPU instances, amount of memory, and other pertinent information. Make sure you remember the admin password you enter, this will be associated with the root account for this server. Also, it is very important that you select "Ubuntu 12 64-bit" as the operating system. Docker relies on pretty new capabilities in the Linux kernel (lxc and cgroups) and is currently only officially supported on the Ubuntu distribution. By the time you read this tutorial this may have changed since the project is moving at an incredible rate. Once you have the server built we need to add a public IP and open the appropriate ports in the firewall. Select your server instance in the UI and you will see a choice for "Add Public IP". You can take the default networking choices but we need to adjust the ports selection. Select "ping", "http", "https", and "ssh". In addition we need to open the specific port range that Docker will be using for container applications so select "custom ports" and open the range 49100-49199.
When we start deploying applications we need to remember that our firewall is blocking all ports except the ones we have explicitly opened. You can look at the server properties to see that the Public IP has been added.
Create New User
It is generally not a good idea to run as root, so in order to update our Ubuntu system and install Docker we will first set up a new user. After giving the new user the appropriate permissions we will logout of root and login as our newly created user. Open your terminal/SSH program and login to your server. Since we are logging in as root the command will be 'ssh [email protected] IP'. From the above screen shot you can see my public IP is 18.104.22.168 and so my command will be 'ssh [email protected]'. The root password is the server admin password you set while creating the server. Create a new user by following these steps:
$ adduser newuser
newuser can be a user name of your choosing. At the prompt create a password for this user and then accept the default user information by pressing ENTER at the prompts. In order to give newuser the correct privileges we must add the user to the sudoers file.
# Edit the sudoers file to add the new user $ /user/sbin/visudo
Add new user in the ‘User privilege specification’ section.
# User privilege specification root ALL=(ALL:ALL) ALL newuser ALL=(ALL:ALL) ALL
Once the file has been successfully edited press CTRL-x to exit the file; and Y to save the changes. Logout as the root user and then login as newuser. We now have a normal user with sufficient privileges to update the Ubuntu operating system and then install Docker.
Update Ubuntu Linux in preparation for Docker Installation
The version of Ubuntu that we installed while creating the server is 12.04 (Precise LTS 64-bit). This particular version of Ubuntu ships with a version 3.2 Linux kernel. In order to get the correct version of LXC that Docker requires we need to update the kernel from 3.2 to version 3.8. The Ubuntu folks at Canonical have made this easy for us by providing backported versions of new kernels. We will be updating Ubuntu Precise to Ubuntu Raring, at the same time will be getting built-in kernel support for AUFS.
# Make sure we are pointed to the correct repositories $ sudo apt-get update # Install the 3.8 kernel $ sudo apt-get install linux-image-generic-lts-raring # Reboot and then login again $ sudo reboot
Once you have the base operating system updated and ready to go it is a pretty straight-forward process to install Docker.
# Add the Docker repository key to the local keychain $ sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 36A1D7869245C8950F966E92D8576A8BA88D21E9 # Add the Docker repository to the list of apt sources $ sudo sh -c "echo deb http://get.docker.io/ubuntu docker main > /etc/apt/sources.list.d/docker.list" # Update the apt files $ sudo apt-get update # Install Docker $ sudo apt-get install lxc-docker
And that is all that is necessary to install Docker!
Validate Docker install
Lastly, let's ensure that Docker is, in fact, correctly installed. The following is a very simple example of how to start an interactive Docker instance, download and run an Ubuntu instance, and then interact with the running container.
# Start a Docker container $ sudo docker run –i –t ubuntu /bin/bash
You will be at a bash prompt within a Docker container. Type ‘echo Hello World from a Docker Container’. This will run the command “echo” inside a container and echo back the string “Hello World from a Docker Container” to standard out. Congratulations! You are now running Docker on Ubuntu within a CenturyLink Cloud server.