Archive for 7th September 2014

Docker Part 2 – HOWTO Remove / Delete Docker Containers

Docker Logo

So you have been messing with docker for a few minutes or hours, and now you have a bunch of either running or stopped containers you no longer need. How do you get rid of them?

Removing Single Containers

To remove a single docker container, you simply start by listing all of the docker containers (started or stopped) to ensure you know which one to delete:

$ sudo docker ps –a


Then remove the chosen container:

$ sudo docker rm <container name>


If the container is currently running you can simply add –f to stop and remove the container in a single command:

$ docker rm -f <container name>


Unless it’s paused, then you will get an error something like the following:

Error response from daemon: Could not kill running container, cannot remove - Container e4f28eccb0cbcfbf4d78104bfe3e84039f62c5073f7301f8a39bb77a9598ae72 is paused. Unpause the container before stopping


This is easy to resolve. The “docker pause” command was added as of Docker 1.0, allowing for better resource utilisation if you have containers you don’t currently need to be wasting CPU cycles. As of Docker 1.1, running containers are also paused during commit activities, to ensure a consistent file system. Simply check the ID of the VM (with a ps command), unpause it, then remove:

sudo docker ps
sudo docker unpause <container id>
sudo docker rm -f <container id>

 

Removing Multiple Containers

Sometimes we have built up a number of containers and we just want to scrub the lot in one go. If you want to remove all containers (running or not), first you need to generate a list of all of the container IDs, then you pass that list to the docker rm command as follows:

sudo docker rm -f $(sudo docker ps -aq)


Alternatively if you wish to remove only the non-running containers:

sudo docker rm $(sudo docker ps -q)

 

That’ll do for now, but in the next post I will go into how to install your first app…

Docker Part 3 – HOWTO Create a Simple Python Web App in Docker

Docker Part 1 – Introduction and HOWTO Install Docker on Ubuntu 14.04 LTS

Docker Logo

So my background is in VMware virtualisation, but I hear the buzz these days is that I may as well forget everything I know, and that it’s all about containers! 🙂

Joking aside, containers definitely compliment virtualisation, giving you more portability, granular control, and the flexibility to spin up new application instances in milliseconds. For an excellent introduction to docker and containers I recommend you check out Greg Ferro’s post here.  I decided it was about time I had a bit of a play with Docker, and at the same time I thought I may as well document my process and some of the basics for any others in the same position. I will try to keep each post as short as possible, breaking things down into manageable chunks (whilst avoiding the dreaded TLDR!).

Most of my recent Linux experience is with Ubuntu, which works out quite well as apparently this is the preferred distro for a very large proportion of Docker users and images. CoreOS is a very interesting proposition too, but one step at a time…

All of the examples in this post and series are based on:

  • Ubuntu 14.04.1 LTS
  • Docker 1.2.0

I find it very interesting to note the rate at which the docker development team are providing new releases.

  • Docker 1.2.0     22 Aug 2014
  • Docker 1.1.0     03 Jul 2014
  • Docker 1.0       09 Jun 2014
  • Docker 0.9       10 Mar 2014
  • Docker 0.8       04 Feb 2014
  • Docker 0.7       26 Nov 2013
  • Docker 0.6       23 Aug 2013

Not only are they very often, but that appear to be accelerating, with a new point release every month for the last three! This is great as it means more features, bug fixes etc, but it also means that anything you develop and test today may already be out of date by the time you come to deploy it to production next month! Docker’s official line on long term support can be found here, but from the look of it you will never be allowed to fall more than 12 months behind. This suggests that the aggressive release schedule to date is likely a pattern that will continue for the foreseeable:
https://www.docker.com/enterprise/support/

Before you follow any of the steps below, I also highly recommend you check out the link below for your first taste of using the Docker CLI:
https://www.docker.com/tryit

If like me, you like to look up a decent book on a subject to help you get your head around it, I also suggest checking out one of the first publications on the subject (I’m reading it at the moment and will try to get a review done once finished):
The Docker Book: Containerization is the new virtualization

So as for the install, it really is incredibly simple. Personally I like to always create my Ubuntu Server VMs as “Minimal” installs. This is simply done by hitting F4 during base OS install. I’ll assume you can do the basic config of your Ubuntu VM by configuring a static IP address, hostname, DNS, installing VMware tools, completing the latest system updates, etc.

The install process is also detailed here:
https://docs.docker.com/installation/ubuntulinux/

To ensure you have your repositories fully up to date:

sudo apt-get update


One you have docker installed log into the console and run the following to install docker and its dependencies:

sudo apt-get install docker.io
sudo ln -sf /usr/bin/docker.io /usr/local/bin/docker
sudo sed -i '$acomplete -F _docker docker' /etc/bash_completion.d/docker.io


I would prefer using the latest version of docker, which means some extra commands:

sudo apt-get install apt-transport-https
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 36A1D7869245C8950F966E92D8576A8BA88D21E9
sudo sh -c "echo deb https://get.docker.io/ubuntu docker main\ > /etc/apt/sources.list.d/docker.list"
sudo apt-get update
sudo apt-get install lxc-docker


As per my previous post you also need to do:

sudo apt-get install apparmor


Check your upgrade has worked by confirming the current version:

sudo docker version


Then you can test the install by creating your first container:

sudo docker run -i -t ubuntu /bin/bash


That’s it!

In the next post I will describe the ways to remove all of the containers you will inevitably create now that you can see the awesome power of Docker! 🙂

Docker Part 2 – HOWTO Remove / Delete Docker Containers

Installing Docker on Ubuntu Quick Fix

Docker Logo

I was installing Docker on Ubuntu (14.04.1 LTS) in my home lab for the first time following the instructions at http://docs.docker.com/installation/ubuntulinux/ this evening and came across an issue.

Docker would not start and was showing the following error:

Cannot connect to the Docker daemon. Is 'docker -d' running on this host?


Checking processes I don’t see docker running:

$ ps -ef | grep docker
alex      3703  2113  0 21:27 pts/0    00:00:00 grep --color=auto docker


Trying to start docker generated the following errors in /var/log/syslog:

kernel: [  608.236848] init: docker main process ended, respawning
kernel: [  608.451873] init: docker main process (4230) terminated with status 1
kernel: [  608.451906] init: docker main process ended, respawning
kernel: [  608.676417] init: docker main process (4280) terminated with status 1
kernel: [  608.676445] init: docker respawning too fast, stopped


After trying a bunch of different fixes which didn’t work, then looked up the docker log at /var/log/upstart/docker.log, which displayed the following:

Error loading docker apparmor profile: fork/exec/sbin/apparmor_parser: no such file or directory ()


A quick install of apparmor fixed this!

$ sudo apt-get install apparmor


And now…

$ ps -ef | grep docker
root      4577     1  0 21:44 ?        00:00:00 /usr/bin/docker -d
alex      4608  2574  0 21:45 pts/0    00:00:00 grep --color=auto docker
$ sudo docker info
Containers: 0
Images: 0
Storage Driver: devicemapper
 Pool Name: docker-8:1-156936-pool
 Pool Blocksize: 64 Kb
 Data file: /var/lib/docker/devicemapper/devicemapper/data
 Metadata file: /var/lib/docker/devicemapper/devicemapper/metadata
 Data Space Used: 291.5 Mb
 Data Space Total: 102400.0 Mb
 Metadata Space Used: 0.7 Mb
 Metadata Space Total: 2048.0 Mb
Execution Driver: native-0.2
Kernel Version: 3.13.0-35-generic
Operating System: Ubuntu 14.04.1 LTS


Happy Days! I hope this saves others some time!

If you found this post useful, check out my Docker HOWTO series – the first post is here:
http://tekhead.it/blog/2014/09/docker-part-1-introduction-and-howto-install-docker-on-ubuntu-14-04-lts/

Cannot See Any iSCSI Devices on Synology from a vSphere Host

Just a quick fix I discovered this weekend. It’s probably quite specific but hopefully if you come across this in future it will save you some time.

I had just finished rebuilding the second node in my lab from 5.1 with a fresh install. I added the software iSCSI initiator and connected it to my iSCSI target (Synology DS412+) using Dynamic Discovery. I then rescanned for a list of devices, and although I was picking up the IQN for the iSCSI server, I couldn’t see any devices!

I tried lots of things including removing and re-adding the initiator, messing with iSCSI bindings, but nothing! Very frustrating.

After a bit of googlage, I came across this KB article from VMware:

Cannot see some or all storage devices in VMware vCenter Server or VirtualCenter (1016222)

Although this was specific to VI3/vSphere 4, it did trigger a thought! Just before I built the new node, I rejigged all of my storage LUNs, deleting 3 old ones in the process (which just so happened to be the first 3 LUNs on my NAS). What I believe this caused is that the LUNs were viewed by node 1 as different LUN IDs on node 2, so they refused to show up!

So now, the fix. Incredibly simple as it turns out:

  1. Created three new temp 10GB LUNs on my old NAS which would then assume LUN IDs 1/2/3 as they originally had (before I deleted them).
  2. Rescan the new node of the cluster for storage
  3. Confirmed all of the LUNs are now visible
  4. Deleted the three temp LUNs from the Synology (I don’t plan to add any more nodes for now so I have no need of these temp LUNs, but as they’re thin provisioned anyway it actually wouldn’t hurt to leave them there).
  5. Rescan the ESXi host again to ensure it can still see the LUNs.
  6. Job done!

Synology iSCSI Devices

Not much to it, but worth a quick post I thought as this simple issue wasted a chunk of my time!

%d bloggers like this: