When I originally set up Octopress, I set it up on my Mac laptop using rvm, as recommended at the time. It worked very well for me until just a few minutes after my last post, when I decided to sync with the upstream changes.
After merging in the changes, I tried to generate my blog again, just to make sure everything worked. Well, it didn’t, and things went downhill from there. The
rake generate command failed because a new gem was required. So, I ran
bundle install to get the latest gems. That failed when a gem required ruby 1.9.3. Then installing ruby 1.9.3 failed in rvm because I needed a newer version of rvm. After banging on that problem for a few minutes, I decided to take a break and come back to the problem later.
Docker to the rescue
Fast forward a few weeks, and I came up with a better idea. I decided to dockerize Octopress. This keeps all the dependencies sanely bottled up in an image that I can run like a command.
Here is the code:
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
How to use it
Then, since rake is set as the entry point, I can run the image as if it were a command. I use the
-v switch to overlay the current blog source over the one cached in the image and
-rm switch to throw away the container when it’s done.
1 2 3 4 5 6 7 8
A few notes
- I had to force the UTF8 locale in order to get ruby to stop complaining about non-ascii characters in the blog entries.
- I add a user called blog with the same UID/GID as my system user, so that any commands that generate files aren’t owned by root. I look forward to proper user namespaces so that I won’t have to do this.
- Deploying the blog doesn’t use my SSH key, as the ‘blog’ user in the image is doing the rsync, not my host system user. I’m ok with typing my password in or just rsync’ing the data directly.
Docker is a great piece of technology, and I keep finding new uses for it.