Docker simplifies software delivery by making it easy to build and share images that contain your application’s entire environment, or application operating system.
What does it mean by application operating system ?
Your application typically require a specific version of operating system, application server, JDK, database server, may require to tune the configuration files, and similarly multiple other dependencies. The application may need binding to specific ports and certain amount of memory. The components and configuration together required to run your application is what is referred to as application operating system.
You can certainly provide an installation script that will download and install these components. Docker simplifies this process by allowing to create an image that contains your application and infrastructure together, managed as one component. These images are then used to create Docker containers which run on the container virtualization platform, provided by Docker.
How is it different from VM?
Docker is an open source container virtualization platform.
What is relationship with Vagrant?
Vagrant is a simplified and portable way to create virtual development environments. It works with multiple virtualization software such as VirtualBox, VMWare, AWS, and more. It also works with multiple configuration software such as Ansible, Chef, Puppet, or Salt.
Starting with version 1.6, Docker containers can be used as one of the backend providers for Vagrant as well. This allows your development environment to be based on Docker containers as opposed to full Virtual Machines. Read more about this at http://docs.vagrantup.com/v2/docker/index.html.
The complete development environment definition is defined in a text file, typically called as ``Vagrantfile''. This file defines the type of machine, software that needs to be installed, networking, and other configuration information.
vagrant up
creates the development environment based upon the configuration defined in the file. vagrant up --provider=aws
will create the development environment for AWS. Similarly vagrant up --provider=docker
will create it for the Docker image.
Docker has three main components:
-
Images are build component of Docker and a read-only template of application operating system.
-
Containers are run component of Docker, and created from, images.Containers can be run, started, stopped, moved, and deleted.
-
Images are stored, shared, and managed in a registry, the distribution component of Docker. This is also known as Docker Hub.
In order for these three components to work together, there is Docker Daemon that runs on a host machine and does the heavy lifting of building, running, and distributing Docker containers. In addition, there is Client that is a Docker binary which accepts commands from the user and communicates back and forth with the daemon.
Client communicates with Daemon, either co-located on the same host, or on a different host. It requests the Daemon to pull an image from the repository using pull
command. The Daemon then downloads the image from Docker Hub, or whatever registry is configured. Multiple images can be downloaded from the registry and installed on Daemon host. Images are run using run
command to create containers on demand.
Docker uses Linux Containers to provide isolation, sandboxing, reproducibility, constraining resources, snapshotting and several other advantages. But that does not mean that mean it can only be used on Linux-based machines.
TBD: Install Docker on your machine using Docker Machine.
Docker daemon and client for different operating systems can be installed from http://docs.docker.com/installation/. As you can see, it can be installed on a wide variety of platforms, including Mac and Windows. Refer to this excellent tutorial for getting started on Windows.
For non-Linux machines, a lightweight Virtual Machine needs to be installed and Daemon is installed within that. A native client is then installed on the machine that communicates with the Daemon.
Download latest Boot2docker installer from https://github.com/boot2docker/osx-installer/releases/latest.
Run the installer to install:
-
VirtualBox VM which is Docker host
-
Docker daemon within the VM
-
Boot2docker management tool
Detailed install instrutions for Mac are at docker.com/installation/mac.
VirtualBox VM can be easily verified by running VirtualBox manager:
TODO: What happens if Mac does not have VirtualBox already installed?
Here is the log from booting Docker daemon on Mac:
bash
unset DYLD_LIBRARY_PATH ; unset LD_LIBRARY_PATH
mkdir -p ~/.boot2docker
if [ ! -f ~/.boot2docker/boot2docker.iso ]; then cp /usr/local/share/boot2docker/boot2docker.iso ~/.boot2docker/ ; fi
/usr/local/bin/boot2docker init
/usr/local/bin/boot2docker up
$(/usr/local/bin/boot2docker shellinit)
docker version
Last login: Mon Jan 5 11:07:35 on ttys003
hello arungupta
~> bash
~> unset DYLD_LIBRARY_PATH ; unset LD_LIBRARY_PATH
~> mkdir -p ~/.boot2docker
~> if [ ! -f ~/.boot2docker/boot2docker.iso ]; then cp /usr/local/share/boot2docker/boot2docker.iso ~/.boot2docker/ ; fi
~> /usr/local/bin/boot2docker init
Virtual machine boot2docker-vm already exists
~> /usr/local/bin/boot2docker up
Waiting for VM and Docker daemon to start...
.o
Started.
Writing /Users/arungupta/.boot2docker/certs/boot2docker-vm/ca.pem
Writing /Users/arungupta/.boot2docker/certs/boot2docker-vm/cert.pem
Writing /Users/arungupta/.boot2docker/certs/boot2docker-vm/key.pem
To connect the Docker client to the Docker daemon, please set:
export DOCKER_HOST=tcp://192.168.59.103:2376
export DOCKER_CERT_PATH=/Users/arungupta/.boot2docker/certs/boot2docker-vm
export DOCKER_TLS_VERIFY=1
~> $(/usr/local/bin/boot2docker shellinit)
Writing /Users/arungupta/.boot2docker/certs/boot2docker-vm/ca.pem
Writing /Users/arungupta/.boot2docker/certs/boot2docker-vm/cert.pem
Writing /Users/arungupta/.boot2docker/certs/boot2docker-vm/key.pem
~> docker version
Client version: 1.3.1
Client API version: 1.15
Go version (client): go1.3.3
Git commit (client): 4e9bbfa
OS/Arch (client): darwin/amd64
Server version: 1.3.2
Server API version: 1.15
Go version (server): go1.3.3
Git commit (server): 39fa2fa
-
Quick demo: compare VirtualBox and Docker bash