Docker in 5 Minutes
This is my first article about Docker based on Feynman Technique. The following article explains Docker basics and summarizes each Docker component with example.
What is Docker?
Docker is a platform or container technology. Docker is an open source engine that automates deployment of any application. Docker consists of a client and server. Client to issue commands and server to do the job and docker daemon listens and execute those commands.
Docker Container Evolution
- Chroot by UNIX (Filesytem isolation)
- FreeBSD jail utility
- Solaris offered containerization tech only limited to Solaris OS
- Virtuozzo by Parallel INC open sourced in 2005
- Google CGroups
- Linux container in 2008
- Docker finally 2013 all pieces brought together to form containerization to mainstream
Surrounding Technologies
- Swarm
- Compose
- Machine
- Kitmatic
- Docker Trusted Registry
- Networking
- Service Delivery (To handle dynamic ip address of containers)
- Orchestration and cluster management (Kubernetes, Mesos)
Docker Container Generation Workflow

Dockerfile
Dockerfile a simple text file. Start with any base image, run one or more commands to create a new image. In the below dockerfile base image is ubuntu with version 15.04.
FROM ubuntu:15.04
ENV foo /bar
WORKDIR ${foo} # WORKDIR /bar
ADD . $foo # ADD . /bar COPY \$foo /quux #
COPY $foo /quuxWhich contains simple below instructions
--------------------------------
| FROM | RUN | ENV |
|COPY | ENTRYPOINT | WORKDIR |
|EXPOSE | CMD | VOLUME |
--------------------------------Dockerfile instructs on how to build image automatically. The dockerfile can be named anything. Best practice to name file ends with filename.dockerfile
Docker build images by reading Dockerfile instructions. $ docker build command is used to build image followed by the file path. Docker daemon validates the docker file and returns error.
$ docker build . #for current directory
$ docker build -f /path/to/dockerfile #you can specify the pathDocker Hub
Docker hub is the github of docker files. Library of public images. You can host your images for free publicly.
Docker Image & Layer

Every instruction in dockerfile will create a layer of image. This layers act like cache, which increases reusability, decreases disk usage and help in speed up docker build. Docker image can also be generated using docker commit command by working on a container this usually used for debugging process.
Images are not containers. Images are like blue prints like class in oop. Images are group of files that are built upon the core OS. They are foundations to create and maintains official images.
When docker mounts the rootfs it starts with read-only, it takes advantage of union mount (aufs) to add read-write file system over read-only files system.
Docker images commands
docker image buildBuild an image from a Dockerfiledocker image importImport the contents from a tarball to create a filesystem imagedocker image inspectDisplay detailed information on one or more imagesdocker image loadLoad an image from a tar archive or STDINdocker image lsList imagesdocker image pruneRemove unused imagesdocker image pullPull an image or a repository from a registrydocker image pushPush an image or a repository to a registrydocker image rmRemove one or more imagesdocker image saveSave one or more images to a tar archive (streamed to STDOUT by default)docker image tagCreate a tag TARGET_IMAGE that refers to SOURCE_IMAGE
Docker Container
Think of a Docker container as another way of virtualization. Virtual Machine(VM) allows sharing of hardware between different VMs to run on isolation. Where as the containers share the OS, running isolated environments.
Containers are a way to package software to run in isolated environments. They are transportable pieces that can run anywhere Linux is running
Connecting containers to outside world
$ docker run -d -p 8000:80 -t nginxInteractive with container
$ docker run -i -t nginx /bin/bash # bash (-i : interactive -t : tty)Additional useful docker container commands
docker containerManage containersdocker execRun a command in a running containerdocker inspectReturn low-level information on Docker objectsdocker killKill one or more running containersdocker logsFetch the logs of a containerdocker psList containersdocker pullPull an image or a repository from a registrydocker rmRemove one or more containersdocker runRun a command in a new containerdocker startStart one or more stopped containersdocker stopStop one or more running containers
Docker Compose
A tool to defining and running complex applications with Docker. It is useful to compose more than one docker containers together. Compose is great for development, testing, and staging environments, as well as CI workflow.
A docker-compose.yml might look like below
version: '3.1' # if no version is specificed then v1 is assumed. Recommend v2 minimumservices: # containers. same as docker run
servicename: # a friendly name. this is also DNS name inside network
image: # Optional if you use build:
command: # Optional, replace the default CMD specified by the image
environment: # Optional, same as -e in docker run
volumes: # Optional, same as -v in docker run
servicename2:volumes: # Optional, same as docker volume createnetworks: # Optional, same as docker network create
When you want to build a application, we need collection of services. In docker you can define each dockerfile or docker image as a service and spin up each container and link the services to communicate with each other.
Docker composer config options
---------------------------------
|build | environment | image |
|networks | volumes | ports |
---------------------------------Additional useful docker compose commands
docker-compose builddocker-compose updocker-compose downdocker-compose logsdocker-compose psdocker-compose stopdocker-compose startdocker-compose rm
A sample docker compose example docker-lemp
Reference
If you have any questions or comments, feel free to write here or on twitter @irfanbaigse.
Tags: docker, docker-machine, docker images, docker containers
Originally published at www.irfanbaigse.info on July 25, 2017.
