Adventures in Docker-land

January 22, 2014

So, after some time away from IT, I’m mucking around in it again to see what seems interesting.

Got a pointer to Docker  from a friend and have been up to my ears ever since.  It’s in a similar vein to the stuff I got to play with when working with Nebula at NASA in the sense that it is a PaaS enabling environment.  It uses thinly provisioned servers (containers) with AUFS (and some support for a few others), so every operation during the image build process resides in a new, thin, COW layer.

This gives great advantages for caching and speeding up the build process.  Also, say you have 2 images that share the same common base build (i.e. apache server), but for one application, you need PHP and the other you need RUBY … build 2 different images from the same base, and instead of wasting 2x the disk space and build time, you have 1x + the difference for PHP in one image and RUBY in the other — and the build time is severely reduced!

Need 5x Apache+PHP servers?  Just run:

docker run -d -t geekmush/apache-php

5x or as many as you want.  There are lots of other options and Docker is being developed actively … and they have some great staff and supporters on!

It’s not worth trying to describe Docker here when they can do a much better job … go check out their website and the Googles!

I’m going to use my space for notes and tips and tricks that I’ve run into during my adventures this week.

Stay tuned!

How to send email through your Google account with Python

June 29, 2007

Seems like a pretty trivial task, yes?

Generally speaking, it is, but I ran into a few fun things that make this worth writing about.


I have a server-side process that I want to send a notice of completion to a customer (and his customer), so I can’t just send it from — I want it to look presentable.

On Solaris, the “mailx” command has the option to change the “From:” address, and that is usually enough to make an e-mail look decent and get past a lot of the relay blockers. I’ve not yet found a similar solution for Linux (although, I’m sure it’s there).

Instead, I wrote a small python script to do this for me. As a bonus, I want to send it through my Google Apps e-mail account (well, a special service account created for this purpose). Sending through Google has the other feature of it is less likely to get blacklisted by some random ISP as our corporate IPs get from time to time.

So, some code …

# Grab the smtp and mxDateTime (excellent Date/Time manipulation
# from eGenix) packages:
import smtplib
from mx.DateTime import *

# We want yesterday’s date
now = now() – RelativeDateTime(days=1)

YEAR = now.year
MONTH = now.month

# Define our GMail auth information
smtpuser = ‘’
smtppass = ‘sekratpassword’

# We have to define the From, To, and BCC addresses
# Note the “toaddrs” needs to be set up with 2 different formats, depending
# where in the mail message it is used
fromaddr = ‘Service Account <>’
toaddrs = ‘,’.split()
bccaddrs = ‘’

# Build the subject line
subject = (“Report For %02d/%02d/%04d” % (MONTH, DAY, YEAR))

# Start building the message with the mail header … again, note the join() used
# on the toaddrs
# NOTE: the placement and number of “\r\n”s are important … if you do not follow
# the RFC, your e-mail won’t get very far!
msg = ("From: %s\r\nTo: %s\r\nBcc: %s\r\nSubject: %s\r\n\r\n" %
(fromaddr, ", ".join(toaddrs), bccaddrs, subject))

# Now append the body of the message.
msg += “Hello,\r\n\r\nYour report is available at:\r\n\r\n”
msg += ”"
msg += "\r\n\r\nRespectfully,\r\n\r\nCustomer Name\r\n"

# Create an SMTP object with the server “” (their outbound mailserver)
server = smtplib.SMTP(‘’)

# Optional, but it gives you a nice view of the conversation for coding/debugging
# purposes

# Start the conversation with EHLO
# Request STARTTLS
# And say EHLO again
# Login to the server with SMTP AUTH now that we’re TLS’d and client identified
server.login(smtpuser, smtppass)
# Finally, send the mail!
server.sendmail(fromaddr, toaddrs, msg)
# Herein lies a hack to work around a bug in this version of python and the
# associated libs. Read more about it here and patch your version, or be lazy
# like me and just trap the Exception and move on with life. 🙂

That’s it in a nutshell.

If I may go back and plug the mxDateTime package from eGenix again, and I may, it’s some nice stuff. They fill the gaps between what the standard python package starts to do and what you really want to do.

In our example above, to get yesterday’s date, it’s as simple as:

now = now() - RelativeDateTime(days=1)

Want the last Monday of the month?

LastMonday = now() + RelativeDateTime(day=28, weekday=(Monday,0))

Granted, that will give you the same time of day as when the line is run, but you can override that with adding the options to RelativeDateTime of:

hour=0, minute=0, second=0

or just use

Fun stuff, I highly recommend their stuff (they have lots of fun packages)

add to del.icio.usDigg itStumble It!Add to Blinkslistadd to furladd to ma.gnoliaadd to simpyseed the vineTailRank