Docker

Overview

Docker containers wrap up a piece of software in a complete filesystem that contains everything it needs to run: code, runtime, system tools, system libraries – anything you can install on a server. This guarantees that it will always run the same, regardless of the environment it is running in.

Docker allows you to package an application with all of its dependencies into a standardized unit for software development.

How is this different from virtual machines?

Containers have similar resource isolation and allocation benefits as virtual machines but a different architectural approach allows them to be much more portable and efficient.

 Virtual Machines

Each virtual machine includes the application, the necessary binaries and libraries and an entire guest operating system - all of which may be tens of GBs in size.

 

Docker Diagram

 

 Containers

Containers include the application and all of its dependencies, but share the kernel with other containers. They run as an isolated process in userspace on the host operating system. They’re also not tied to any specific infrastructure – Docker containers run on any computer, on any infrastructure and in any cloud.

 

Virtual Machine Diagram


Installing Docker CentOS 6.5

Installing Docker on CentOS-6 requires the use of the EPEL repository. Once you have enabled EPEL you may continue with the rest of the installation

To install docker on CentOS-6 install the docker-io package with the following command:

  • $ sudo yum install docker-io

Once docker is installed, you will need to start the service in order to use it.

  • $ sudo service docker start

To start the docker service on boot:

  • $ sudo chkconfig docker on

Create Docker Image

By default, docker must be run as root, or via sudo privileges.

The docker packages intentionally omit the creation of the docker group, as it allows for trivial root escalation on the host.

To get the latest stable official CentOS image on Docker Hub:

  • $ sudo docker pull centos

This command only pulls the image tagged centos:latest, which always points to the latest stable CentOS release, currently CentOS 7 (centos:centos7). To pull any other version of the CentOS image, for example CentOS 6:

  • $ sudo docker pull centos:centos6

To verify the images have been fetched locally:

  • $ sudo docker images centos

Create Docker Container

Show docker images.

  • $ docker images

Create a container based in image

  • sudo docker run -d --privileged=true --name my_container  -i -t centos:centos6 /bin/bash

Running basic commands

Show docker images.

  • $ docker images

Show all container created.

  • $ docker ps -a

Show all containers are running.

  • $ docker ps

Start a docker container.

  • $ docker start <container-id>

We can now attach to the container to create a shell where we can make our modifications.

  • $ docker attach <container-id>

Once modified exit and save changes with a commit

  • $ exit

Create an image based on a container

  • $ docker ps
  • $ docker stop <Container-ID>
  • $ docker commit <Container-ID> <new-image-name:version>