Professional Documents
Culture Documents
Over Christmas/New Years I had a fair amount of spare time for relaxation; so naturally this was
spent tinkering around with various bits of software and kit I havent had time to play with during
the past few months. One of the things I wanted to test and try in anger was Docker; a
wrapper/software suite that wraps LXC into something a bit more usable. There is a video below
that explains what Docker is and how it works:
One of the biggest benefits of Docker is with a bit of skill, it allows you to satisfy your tech
curiosity without compromising your production environments / home environments, i.e. Oh
cock, I spent 2 hours playing around with X and getting it working and its actually not very
good; now i have to go remove databases, apache entries, etc. In Docker, you can simply just
spin up a new ubuntu container (instance; like a virtual machine essentially if you think
abstract), play around and develop for a few hours, then either save it, or crash and burn it
without any impact to your underlying server.
This is perfect for those of us who can spend 8+ hours testing out redis across 5 servers, or
elasticsearch with packetbeat, etc yet dont want to spend 30 minutes making a new virtual
machine (KVM ftw), or even worse running it on our stable kit.
Therefore the purpose of this blog is give you all the tools and commands to turn Docker into
something useful that you can use on a daily basis. So, lets begin!
1. Getting started
At home I run Ubuntu 14.04 as my operating system of choice, therefore all instructions
pertaining to the installation of Docker are for Ubuntu (Debian too, I imagine) if you require
RHEL/Centos then follow the guide here.
For detailed instructions (and per platform instructions), follow the Docker on Ubuntu
installation guides here but for brevitys sake, here are the steps you need to take in order to get
docker ready to roll on Ubuntu 14.04:
1
2
3
4
5
6
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
[OK]
neurodebian NeuroDebian provides neuroscience research... 4 [OK]
shuron/debian-openjdk-7 Open JDK 7 64x on plain debian (Jessie) La... 2 [OK]
webhippie/cedarish-debian Heroku cedar-ish base images for Docker bu... 2 [OK]
jesselang/debian-vagrant Stock Debian Images made Vagrant-friendly ... 1 [OK]
maxexcloo/debian Docker base image built on Debian with Sup... 1 [OK]
tutum/debian Debian image with SSH access. For the root... 1 [OK]
mschuerig/debian-subsonic Subsonic 5.0 on Debian/wheezy. 1 [OK]
fike/debian-postgresql PostgreSQL 9.4 beta until 9.0 version runn... 1 [OK]
jprjr/debian-nginx 1 [OK]
icco/simple-debian A debian build with Ruby 2.1 installed and... 1 [OK]
calebj/debian 0 [OK]
eboraas/debian Debian base images, for all currently-avai... 0 [OK]
thedutchselection/debian 0 [OK]
yaronr/debian-wheezy Debian Wheezy, 85mb, with a few extras 0 [OK]
aostanin/debian 0 [OK]
razmo/debian Debian base 0 [OK]
takeshi81/debian-wheezy-php Debian wheezy based PHP repo. 0 [OK]
tianon/debian-devel 0 [OK]
etna/drone-debian 0 [OK]
essembeh/debian My own Debian Jessie image 0 [OK]
kalabox/debian Kalabox Debian Wheezy image for all the ot... 0 [OK]
reinblau/debian Debian with usefully default packages for ... 0 [OK]
root@server:/home/sam#
Here we can see a number of images that contain the word Debian; the one at the top has the
most stars and is also a semi official image (??), so lets use that one! To download it locally, use
the pull command as below:
1 root@server:/home/sam# docker pull debian
2 debian:latest: The image you are pulling has been verified
Now that the image has been downloaded, lets go ahead and deploy a container based on the
image so we can get cracking and start to use Debian!
1 root@server:/home/sam# docker run -it --name debserver debian /bin/bash
2 root@dc4e5b4e5311:/#
Within seconds (i.e. <3 seconds), we now have a container running Debian ontop of our Ubuntu
14.04 server, cool hey! To prove this is a Debian box and not Ubuntu, you can go ahead and
install lsb_release (apt-get update & apt-get install lsb-release), and run it:
1 root@dc4e5b4e5311:/# lsb_release -a
2 No LSB modules are available.
3 Distributor ID: Debian
4 Description: Debian GNU/Linux 7.7 (wheezy)
5 Release: 7.7
6 Codename: wheezy
7 root@dc4e5b4e5311:/#
Cool huh! Now, you can go ahead and tinker to your hearts content, set stuff up, install apache,
etc and its all safely contained within Docker. To shutdown the container, simply exit the shell:
1 root@dc4e5b4e5311:/# exit
2 exit
3
4
5
6
7
You can then restart it using the command docker start, as below:
1 root@server:/home/sam# docker start debserver
2 debserver
3 root@server:/home/sam# docker ps -as
4 CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES SIZE
5 dc4e5b4e5311 debian:latest "/bin/bash" 3 minutes ago Up 1 seconds debserver 39.1 MB
6 283ac561a135 centos:centos7 "/bin/bash" 12 minutes ago Up 12 minutes CentosBox 5 B
7 root@server:/home/sam#
And if you want to view the IP address without having to go into the container, run the
command:
1 root@server:/home/sam# docker inspect debserver | grep IPAddress
2 "IPAddress": "172.17.0.8",
3 root@server:/home/sam#
If you do wish to connect to the console again, run the attach command:
1 root@server:/home/sam# docker attach debserver
2 root@dc4e5b4e5311:/#
One of the coolest things about Docker, in my opinion, is the ability to save your containers
locally for re-use in the future.
Say for example, I wanted to install my companies software / configure a series of packages and
software on my Debian box and then save it locally so i can quickly deploy it in the future.
After installing apache2, mysql-server, and configuring so your super happy with your Debian
container, you can use the commit command to save the container locally:
1 root@server:/home/sam# docker commit debserver smnet
2 34c640602df03c496e67e64d51c557255f6206a521570bd9d22812ae0736124a
Then, in a minute, or years time, i can easily redeploy that Debian container that i installed lsbrelease on, using the command:
1 root@server:/home/sam# docker run -it --name debserver2 smnet /bin/bash
2 root@614ede51e5f8:/# lsb_release -a
3 No LSB modules are available.
4 Distributor ID: Debian
5 Description: Debian GNU/Linux 7.7 (wheezy)
6 Release: 7.7
7 Codename: wheezy
8 root@614ede51e5f8:/#
Very cool! This is so powerful for a development and testing perspective as it allows you to
RAPIDLY spin up a large number of platforms (Ubuntu, RHEL, you name it) and configure
them as you like. You can then rapidly and safely tear them down, or save them locally to be
redeployed back onto the same box, or sent to other servers to be deployed there very
awesome.
One final thing removing images! Say you dont like smnet anymore, you can simply remove it
using the command rmi (ReMove Image):
1 root@server:/home/sam# docker images
2 REPOSITORY
3 smnet
TAG
latest
4 opsview46-trusty latest
5 debian
latest
IMAGE ID
34c640602df0
CREATED
30 minutes ago
d761a27fa999
479215127fa7
3 days ago
4 days ago
VIRTUAL SIZE
124.1 MB
1.029 GB
84.99 MB