Getting Started with Docker

A few months back I taught a workshop for the FullStack Community in Cluj regarding this very subject, Getting started with Docker. Given the popularity of the subject and the positive review of the workshop, I decided to start writing this series in which I plan to cover the basics of Docker, Docker Compose, Open Stack and Jenkins, culminating in Continuous Delivery with Docker, Jenkins on Open Stack.


So, why Docker?

Docker innovated over the virtual machine architecture popular at the time by the simple fact that a Docker container runs natively on Linux and shares the kernel of the host machine with other containers. It runs as a discrete process, taking no more memory than any other executable, making it lightweight. By contrast, a virtual machine (VM) runs a full-blown “guest” operating system with virtual access to host resources through a hypervisor. In general, VMs provide an environment with more resources than most applications need.


Installation

I'm going to skip over the installation process and just link to their documentation since is very well written.

Mac Os X

Windows

Linux


Concepts

Docker introduced three basic concepts to describe how the end user should interact with the stack.

Dockerfile

A Dockerfile is a text document that contains all the commands a user could call on the command line to assemble an image.

Docker Image

An image is an executable package that includes everything needed to run an application–the code, a runtime, libraries, environment variables, and configuration files.

Docker Container

A container is a runtime instance of an image–what the image becomes in memory when executed (that is, an image with state, or a user process).

Ususal commands

  • docker build -t <tag> . build a docker image with a set <tag>.
  • docker images list all docker images
  • docker rmi <image-id> remove an image
  • docker run -d --name <name> -p <port> -e <env> -v <host>:<path> <image> start a container with the name <name> running on port <port> with env variables <env> with <host> folder mapped to <path> in container based on <image>
  • docker ps list all running containers
  • docker ps -a list all containers running or not
  • docker stop <container> stop a running container
  • docker restart <container> restart a running container

In conclusion, if you got this far you should at least have a basic grasp of what Docker is and what it does.


References