---
# System prepended metadata

title: Docker

---

# Docker

**What is Container?**
Container provides the ability to package and run an application in a loosely isolated environment called a container. The isolation and security allow you to run many containers simultaneously on a given host. This means you can run more containers on a given hardware combination than if you were using virtual machines.

Containerization allows developers to create and deploy applications faster and more securely. With traditional methods, code is developed in a specific computing environment which, when transferred to a new location, often results in bugs and errors. For example, when a developer transfers code from a desktop computer to a virtual machine (VM) or from a Linux to a Windows operating system. Containerization eliminates this problem by bundling the application code together with the related configuration files, libraries, and dependencies required for it to run. This single package of software or “container” is abstracted away from the host operating system, and hence, it stands alone and becomes portable—able to run across any platform or cloud, free of issues.

![](https://i.imgur.com/9Sr7pn2.png)


 
# **Benefits**
Containerization offers significant benefits to developers and development teams. Among these are the following:

**Portability:** A container creates an executable package of software that is abstracted away from (not tied to or dependent upon) the host operating system, and hence, is portable and able to run uniformly and consistently across any platform or cloud. 

**Agility:** The open source Docker Engine for running containers started the industry standard for containers with simple developer tools and a universal packaging approach that works on both Linux and Windows operating systems. The container ecosystem has shifted to engines managed by the Open Container Initiative (OCI). Software developers can continue using agile or DevOps tools and processes for rapid application development and enhancement.

**Speed**: Containers are often referred to as “lightweight,” meaning they share the machine’s operating system (OS) kernel and are not bogged down with this extra overhead. Not only does this drive higher server efficiencies, it also reduces server and licensing costs while speeding up start-times as there is no operating system to boot.

**Fault isolation:** Each containerized application is isolated and operates independently of others. The failure of one container does not affect the continued operation of any other containers. Development teams can identify and correct any technical issues within one container without any downtime in other containers. Also, the container engine can leverage any OS security isolation techniques—such as SELinux access control—to isolate faults within containers.

**Efficiency:** Software running in containerized environments shares the machine’s OS kernel, and application layers within a container can be shared across containers. Thus, containers are inherently smaller in capacity than a VM and require less start-up time, allowing far more containers to run on the same compute capacity as a single VM. This drives higher server efficiencies, reducing server and licensing costs.
Ease of management: A container orchestration platform automates the installation, scaling, and management of containerized workloads and services.

**Security:** The isolation of applications as containers inherently prevents the invasion of malicious code from affecting other containers or the host system. Additionally, security permissions can be defined to automatically block unwanted components from entering containers or limit communications with unnecessary resources.

# Types of Containers Engine
* Docker
* CoreOS rkt
* Mesos Containerizer
* LXC Linux Containers
* OpenVZ
* containerd

# Docker installation 

1. SET UP THE REPOSITORY
Update the apt package index and install packages to allow apt to use a repository over HTTPS:

```
$ sudo apt-get update

$ sudo apt-get install \
    apt-transport-https \
    ca-certificates \
    curl \
    gnupg-agent \
    software-properties-common
```
2. Add Docker’s official GPG key:

`$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -`



3. Use the following command to set up the stable repository.

```
$ sudo add-apt-repository \
   "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
   $(lsb_release -cs) \
   stable"
```
**INSTALL DOCKER ENGINE**

1. Update the apt package index, and install the latest version of Docker Engine and containerd, or go to the next step to install a specific version:

```
 $ sudo apt-get update
 $ sudo apt-get install docker-ce docker-ce-cli containerd.io
```
2. Verify that Docker Engine is installed correctly by running the hello-world image.

`$ sudo docker run hello-world`

Post-installation steps for Linux

To create the docker group and add your user:

1. Create the docker group.

`$ sudo groupadd docker`

2. Add your user to the docker group.

`$ sudo usermod -aG docker $USER`

Log out and log back in so that your group membership is re-evaluated.

# Running a Simple Docker Application

`docker run -it --rm -d -p 8080:80 --name web nginx`

# Create New Docker Image
1. Create a folder named `myfristdockercontainer`
```
mkdir myfristdockercontainer
cd myfristdockercontainer
```

2. Now lets create a `Dockerfile` and copy the contents from this [file](https://raw.githubusercontent.com/kvenkata986/helm-meetup/master/images/helm-meetup/Dockerfile). Note: D should be always caps

`vi Dockerfile`

3. Lets create a folder named `files` and a file called `index.html` and copy the contents from this [link](https://raw.githubusercontent.com/kvenkata986/helm-meetup/master/images/helm-meetup/files/index.html) to `files/index.html` 
```
mkdir files
vi files/index.html
```
4. Now lets create a Docker Image from the `Dockerfile`. `aditya/myfristwebapp` is the image name.

`docker build -t aditya/myfristwebapp .`

5. Now lets run the conatiner(application) named  `web`

`docker run -it --rm -d -p 8080:80 --name web aditya/myfristwebapp`

6. To list the running containers

`docker ps`

7. To kill a container

`docker kill <name of the container>`