How To Install Docker step by step
How To Install and Use Docker: Getting Started
Introduction
The docker project offers higher-level tools, working together, which are built on top of some Linux kernel features. The goal is to help developers and system administrators port applications - with all of their dependencies conjointly - and get them running across systems and machines - with no troubles.
Docker achieves this by creating safe, LXC (i.e. Linux Containers) based environments for applications called docker containers. Creating containers using docker images, which can be built either by executing commands manually or automatically through Dockerfiles.
Docker is here to offer you an efficient, speedy way to port applications across systems and machines. It is light and lean, allowing you to quickly contain applications and run them within their own secure environments (via Linux Containers: LXC).
We aim to thoroughly introduce you to Docker: one of the most exciting and powerful open-source projects to come to life in the recent years. Docker can help you with so much it’s unfair to attempt to summarise its capabilities in one sentence.
Use cases are limitless and the need has always been there.
Glossary
1. Docker
2. The Docker Project and its Main Parts
3. Docker Elements
- Docker Containers
- Docker Images
- Dockerfiles
4. How to Install Docker
5. How To Use Docker
- Beginning
- Working with Images
- Working with Containers
Docker
Whether it be from your development machine to a remote server for production, or packaging everything for use elsewhere, it is always a challenge when it comes to porting your application stack together with its dependencies and getting it to run without hiccups. In fact, the challenge is immense and solutions so far have not really proved successful for the masses.
In a nutshell, docker as a project offers you the complete set of higher-level tools to carry everything that forms an application across systems and machines - virtual or physical - and brings along loads more of great benefits with it.
Docker achieves its robust application (and therefore, process and resource) containment via Linux Containers (e.g. namespaces and other kernel features). Its further capabilities come from a project's own parts and components, which extract all the complexity of working with lower-level linux tools/APIs used for system and application management with regards to securely containing processes.
The Docker Project and its Main Parts
Docker project (open-sourced by dotCloud in March '13) consists of several main parts (applications) and elements (used by these parts) which are all [mostly] built on top of already existing functionality, libraries and frameworks offered by the Linux kernel and third-parties (e.g. LXC, device-mapper, aufs etc.).
Main Docker Parts
- docker daemon: used to manage docker (LXC) containers on the host it runs
- docker CLI: used to command and communicate with the docker daemon
- docker image index: a repository (public or private) for docker images
Main Docker Elements
- docker containers: directories containing everything-your-application
- docker images: snapshots of containers or base OS (e.g. Ubuntu) images
- Dockerfiles: scripts automating the building process of images
Docker Elements
The following elements are used by the applications forming the docker project.
Docker Containers
The entire procedure of porting applications using docker relies solely on the shipment of containers.
Docker containers are basically directories which can be packed (e.g. tar-archived) like any other, then shared and run across various different machines and platforms (hosts). The only dependency is having the hosts tuned to run the containers (i.e. have docker installed). Containment here is obtained via Linux Containers (LXC).
LXC (Linux Containers)
Linux Containers can be defined as a combination various kernel-level features (i.e. things that Linux-kernel can do) which allow management of applications (and resources they use) contained within their own environment. By making use of certain features (e.g. namespaces, chroots, cgroups and SELinux profiles), the LXC contains application processes and helps with their management through limiting resources, not allowing reach beyond their own file-system (access to the parent's namespace) etc.
Docker with its containers makes use of LXC, however, also brings along much more.
Docker Containers
Docker containers have several main features.
They allow;
- Application portability
- Isolating processes
- Prevention from tempering with the outside
- Managing resource consumption
and more, requiring much less resources than traditional virtual-machines used for isolated application deployments.
They do not allow;
- Messing with other processes
- Causing "dependency hell"
- Or not working on a different system
- Being vulnerable to attacks and abuse all system's resources
and (also) more.
Being based and depending on LXC, from a technical aspect, these containers are like a directory (but a shaped and formatted one). This allows portability and gradual builds of containers.
Each container is layered like an onion and each action taken within a container consists of putting another block (which actually translates to a simple change within the file system) on top of the previous one. And various tools and configurations make this set-up work in a harmonious way altogether (e.g. union file-system).
What this way of having containers allows is the extreme benefit of easily launching and creating new containers and images, which are thus kept lightweight (thanks to gradual and layered way they are built). Since everything is based on the file-system, taking snapshots and performing roll-backs in time are cheap(i.e. very easily done / not heavy on resources), much like version control systems (VCS).
Each docker container starts from a docker image which forms the base for other applications and layers to come.
Docker Images
Docker images constitute the base of docker containers from which everything starts to form. They are very similar to default operating-system disk images which are used to run applications on servers or desktop computers.
Having these images (e.g. Ubuntu base) allow seamless portability across systems. They make a solid, consistent and dependable base with everything that is needed to run the applications. When everything is self-contained and the risk of system-level updates or modifications are eliminated, the container becomes immune to external exposures which could put it out of order - preventing the dependency hell.
As more layers (tools, applications etc.) are added on top of the base, new images can be formed bycommitting these changes. When a new container gets created from a saved (i.e. committed) image, things continue from where they left off. And the union file system, brings all the layers together as a single entity when you work with a container.
These base images can be explicitly stated when working with the docker CLI to directly create a new container or they might be specified inside a Dockerfile for automated image building.
Dockerfiles
Dockerfiles are scripts containing a successive series of instructions, directions, and commands which are to be executed to form a new docker image. Each command executed translates to a new layer of the onion, forming the end product. They basically replace the process of doing everything manually and repeatedly. When a Dockerfile is finished executing, you end up having formed an image, which then you use to start (i.e. create) a new container.
How To Install Docker
At first, docker was only available on Ubuntu. Nowadays, it is possible to deploy docker on RHEL based systems (e.g. CentOS) and others as well.
Let's quickly go over the installation process for Ubuntu.
Installation Instructions for Ubuntu
The simplest way to get docker, other than using the pre-built application image, is to go with a 64-bit Ubuntu 14.04 VPS
Update your droplet:
sudo apt-get update
sudo apt-get -y upgrade
Make sure aufs support is available:sudo apt-get install linux-image-extra-uname -r
Add docker repository key to apt-key for package verification:sudo apt-key adv --keyserver hkp://pgp.mit.edu:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D
Add the docker repository to Apt sources:echo "deb https://apt.dockerproject.org/repo ubuntu-trusty main" | sudo tee /etc/apt/sources.list.d/docker.list
Update the repository with the new addition:sudo apt-get update
Finally, download and install docker:sudo apt-get install docker-engine
Ubuntu's default firewall (UFW: Uncomplicated Firewall) denies all forwarding traffic by default, which is needed by docker.
Enable forwarding with UFW:
Edit UFW configuration using the nano text editor.sudo nano /etc/default/ufw
Scroll down and find the line beginning with DEFAULT_FORWARD_POLICY.
Replace:DEFAULT_FORWARD_POLICY="DROP"
With:
DEFAULT_FORWARD_POLICY="ACCEPT"
Press CTRL+X and approve with Y to save and close.
Finally, reload the UFW:sudo ufw reload
Read our post on how to use Docker here and please check out docker's documentation for installation or for a full set of instructions here.