Intro
Docker provides an integrated technology suite that enables development and IT operations teams to build, ship, and run distributed applications anywhere.
“Docker wasn’t on anyone’s roadmap in 2014, it is on everyone’s roadmap for 2015” @adrianco
Terminology
- Docker Images – blueprints of our application
- Docker Container – created from docker images and are real instances of our application
- Docker Daemon – building, running and distributing Docker images
- Docker Client – Run on our local machine and connect to the daemon
- Docker Hub – a registry of docker images
Installation
Quick and easy install script provided by Docker:
1 |
curl -sSL https://get.docker.com/ | sh |
If you’re looking for detailed steps or how to install on different Windows / OSX please check https://docs.docker.com/
If you’re running docker under Linux you need to run
1 |
sudo usermod -aG docker <your-username> |
to avoid: Cannot connect to the Docker daemon. Is the docker daemon running on this host? Log out and log in back. This ensures your user is running with the correct permissions.
On Linux the 3.10.x kernel is the minimum requirement for Docker. For OSX 10.8 “Mountain Lion” or newer is required.
Both OSX and Windows require Docker Toolbox to be installed in order to be able to run docker containers.
Early versions of Docker Toolbox require you to install a VM with Docker Machine using the VirtualBox provider:
1 2 3 |
$ docker-machine create --driver=virtualbox default $ docker-machine ls $ eval "$(docker-machine env default)" |
However the latest versions of Docker Toolbox will take care of this part. You can check Docker-machine version and status and ip:
1 2 3 4 5 6 7 8 9 10 |
$ docker-machine version C:\Program Files\Docker Toolbox\docker-machine.exe version 0.5.2 ( 0456b9f ) $ docker-machine env default export DOCKER_TLS_VERIFY="1" export DOCKER_HOST="tcp://192.168.99.100:2376" export DOCKER_CERT_PATH="C:\Users\demo\.docker\machine\machines\default" export DOCKER_MACHINE_NAME="default" # Run this command to configure your shell: # eval "$(C:\Program Files\Docker Toolbox\docker-machine.exe env default)" |
1 2 3 |
BLUEONE+demo@BlueOne MINGW64 ~ $ docker-machine status default Running |
Docker Images
Docker at its core is a way to separate an application and the dependencies needed to run it from the operating system itself. To make this possible Docker uses containers and images.
A Docker image is basically a template for a filesystem. When you run a Docker image, an instance of this filesystem is made live and runs on your system inside a Docker container. By default this container can’t touch the original image itself or the filesystem of the host where Docker is running. It’s a self-contained environment.
Let’s search the official Ubuntu docker image.
- docker search – search images by name
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
$ docker search ubuntu NAME DESCRIPTION STARS OFFICIAL AUTOMATED ubuntu Ubuntu is a Debian-based Linux operating s... 2789 [OK] ubuntu-upstart Upstart is an event-based replacement for ... 48 [OK] sequenceiq/hadoop-ubuntu An easy way to try Hadoop on Ubuntu 26 [OK] torusware/speedus-ubuntu Always updated official Ubuntu docker imag... 25 [OK] ubuntu-debootstrap debootstrap --variant=minbase --components... 20 [OK] tleyden5iwx/ubuntu-cuda Ubuntu 14.04 with CUDA drivers pre-installed 18 [OK] rastasheep/ubuntu-sshd Dockerized SSH service, built on top of of... 15 [OK] n3ziniuka5/ubuntu-oracle-jdk Ubuntu with Oracle JDK. Check tags for ver... 5 [OK] sameersbn/ubuntu 5 [OK] nuagebec/ubuntu Simple always updated Ubuntu docker images... 4 [OK] nimmis/ubuntu This is a docker images different LTS vers... 3 [OK] maxexcloo/ubuntu Docker base image built on Ubuntu with Sup... 2 [OK] seetheprogress/ubuntu Ubuntu image provided by seetheprogress us... 1 [OK] sylvainlasnier/ubuntu Ubuntu 15.04 root docker images with commo... 1 [OK] isuper/base-ubuntu This is just a small and clean base Ubuntu... 1 [OK] densuke/ubuntu-jp-remix Ubuntu Linuxremix 1 [OK] rallias/ubuntu Ubuntu with the needful 0 [OK] tvaughan/ubuntu https://github.com/tvaughan/docker-ubuntu 0 [OK] esycat/ubuntu Ubuntu LTS 0 [OK] konstruktoid/ubuntu Ubuntu base image 0 [OK] zoni/ubuntu 0 [OK] teamrock/ubuntu TeamRock's Ubuntu image configured with AW... 0 [OK] birkof/ubuntu Ubuntu 14.04 LTS (Trusty Tahr) 0 [OK] partlab/ubuntu Simple Ubuntu docker images. 0 [OK] densuke/ubuntu-supervisor densuke/ubuntu-jp-remix:trusty supe... 0 [OK] |
Limit the search to Ubuntu images with at least 1000 stars/rating:
1 2 3 4 |
BLUEONE+demo@BlueOne MINGW64 ~ $ docker search -s 1000 ubuntu NAME DESCRIPTION STARS OFFICIAL AUTOMATED ubuntu Ubuntu is a Debian-based Linux operating s... 2789 [OK] |
- docker run – run and interact with the image:
1 2 3 |
BLUEONE+demo@BlueOne MINGW64 ~ $ docker run -it ubuntu ./bin/bash root@1fd0654363a9:/# |
- docker exec – SSH on a container:
1 |
docker exec -i -t <instance_id> bash |
- docker images – shows the list of docker images:
1 2 3 4 5 |
BLUEONE+demo@BlueOne MINGW64 ~ $ docker images REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE ubuntu latest 89d5d8e8bafb 18 hours ago 187.9 MB hello-world latest 0a6ba66e537a 8 weeks ago 960 B |
- docker ps – List of running instances:
1 2 3 4 |
BLUEONE+demo@BlueOne MINGW64 ~ $ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 1fd0654363a9 ubuntu "./bin/bash" 10 minutes ago Up 10 minutes serene_panini |
View previous images and history:
1 2 3 4 5 6 7 |
BLUEONE+demo@BlueOne MINGW64 ~ $ docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 1fd0654363a9 ubuntu "./bin/bash" 12 minutes ago Exited (127) 12 seconds ago serene_panini ec638626f2c4 ubuntu "-t" 2 hours ago Created suspicious_poincare 59262b38036c ubuntu "/bin/bash" 2 hours ago Exited (0) 2 hours ago sad_swirles cbeafb0682f9 8574d741d86b "/bin/bash" 5 days ago Exited (1) 5 days ago tender_newton |
- docker inspect – how to retrieve Docker container’s internal IP address:
1 |
docker inspect <container_id> |
or
1 |
docker inspect -f '{{ .NetworkSettings.IPAddress }}' <container_id> |
docker import
creates an image from a tarball.docker build
creates image from Dockerfile.docker commit
creates image from a container, pausing it temporarily if it is running.
1 2 3 |
BLUEONE+demo@BlueOne MINGW64 ~ $ docker commit -a itabara 1fd0654363a9 ubuntu-node:0.1 a526b046051e64ac8cc943cec1afe2210cbee99c7202ea728a77c027a55b0bc1 |
docker rmi
removes an image.
1 |
docker rmi -f "image name/ image id" |
Remove docker instance:
1 2 3 |
# docker ps -a # docker rm daf644660736 |
While you can use the docker rmi
command to remove specific images, there’s a tool called docker-gc that will clean up images that are no longer used by any containers in a safe manner.
docker load
loads an image from a tar archive as STDIN, including images and tags (as of 0.7).docker save
saves an image to a tar archive stream to STDOUT with all parent layers, tags & versions (as of 0.7).docker history
shows history of image.docker tag
tags an image to a name (local or registry).
Containers
Docker containers wrap up your application 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.
Containers are for software, not for data
Docker containers are consumables. Docker containers should be used to scale applications, for firing more app servers with the same setup etc. Data belongs onto the filesystem but not into a container that can neither be cloned in an easy way nor incrementally backed up in a reasonable way. Containers are for software, not for data.
Docker container commands
docker create
creates a container but does not start it.docker run
creates and starts a container in one operation.docker rm
deletes a container.docker update
updates a container’s resource limits.
If you want to map a directory on the host to a docker container, docker run -v $HOSTDIR:$DOCKERDIR
. Also see Volumes.
docker start
starts a container so it is running.docker stop
stops a running container.docker restart
stops and starts a container.docker pause
pauses a running container, “freezing” it in place.docker unpause
will unpause a running container.docker wait
blocks until running container stops.docker kill
sends a SIGKILL to a running container.docker attach
will connect to a running container.docker logs
gets logs from container. (You can use a custom log driver, but logs is only available forjson-file
andjournald
in 1.10)docker inspect
looks at all the info on a container (including IP address).docker events
gets events from container.docker port
shows public facing port of container.docker top
shows running processes in container.docker stats
shows containers’ resource usage statistics.docker diff
shows changed files in the container’s FS.docker stats --all
shows a running list of containers.
Additional links: