Docker

12
Docker: A how-to 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

description

Docker instructions

Transcript of Docker

Docker: A how-toOver 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 startedAt 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 guidehere.For detailed instructions (and per platform instructions), follow the Docker on Ubuntu installation guideshere but for brevitys sake, here are the steps you need to take in order to get docker ready to roll on Ubuntu 14.04:123456apt-get installapt-transport-httpssudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 36A1D7869245C8950F966E92D8576A8BA88D21E9sudo sh -c "echo deb https://get.docker.com/ubuntu docker main\> /etc/apt/sources.list.d/docker.list"sudo apt-get updatesudo apt-get install lxc-docker

To test that everything worked, run:1docker ps -as

This should return the following:123root@server:/home/sam# docker ps -asCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES SIZEroot@server:/home/sam#

If you get:12root@server:/home/sam# docker ps -asFATA[0000] Cannot connect to the Docker daemon. Is 'docker -d' running on this host?

Then the Docker service isnt running. On Ubuntu, run service docker start, and re run docker ps -as, and it should now work.2. Using DockerSo now youve got Docker, how do you actually use it!?Docker works using containers which are essentially your virtual machines, if you are familiar with virtualization. You can view all your containers by running docker ps -as, as below:1234root@server:/home/sam# docker ps -asCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES SIZE283ac561a135 centos:centos7 "/bin/bash" 14 seconds ago Up 3 seconds CentosBox 5 Broot@server:/home/sam#

As you can see, I have a single container called CentosBox running that is of the type centos:centos7. The container ID is283ac561a135, which can be used if you dont give your container a human name (i.e. CentosBox!).So how did i get a Centos container and how does it work? Docker works using something called images, which are essentially templates (like virtual appliances, essentially). You can create your own image, share it with others, and vice versa, use other peoples images on your box. To find an image you can run the command:1docker search

See below for an example:12345678910111213141516171819202122232425262728root@server:/home/sam# docker search debianNAME DESCRIPTION STARS OFFICIAL AUTOMATEDdebian (Semi) Official Debian base image. 291 [OK]google/debian 30 [OK]hanswesterbeek/google-debian-oracle-jdk Oracle's JDK installed on top of Google's ... 4 [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:1234567root@server:/home/sam# docker pull debiandebian:latest: The image you are pulling has been verified1aeada447715: Pull complete479215127fa7: Pull complete511136ea3c5a: Already existsStatus: Downloaded newer image for debian:latestroot@server:/home/sam#

Now lets make sure that it has been downloaded; run the images command to view all the images stored locally on your Docker server:1234root@server:/home/sam# docker imagesREPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZEdebian latest 479215127fa7 4 days ago 84.99 MBroot@server:/home/sam#

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!12root@server:/home/sam# docker run -it --name debserver debian /bin/bashroot@dc4e5b4e5311:/#

Within seconds (i.e.