Convert Any Server to a Docker Container






This post is based on material from Docker in Practice, available on Manning’s Early Access Program. Get 39% off with the code: 39miell


How and Why?

Let’s say you have a server that has been lovingly hand-crafted that you want to containerize.

Figuring out exactly what software is required on there and what config files need adjustment would be quite a task, but fortunately blueprint exists as a solution to that.

What I’ve done here is automate that process down to a few simple steps. Here’s how it works:


You kick off a ShutIt script (as root) that automates the bash interactions required to get a blueprint copy of your server, then this in turn kicks off another ShutIt script which creates a Docker container that provisions the container with the right stuff, then commits it. Got it? Don’t worry, it’s automated and only a few lines of bash.

There are therefore 3 main steps to getting into your container:

– Install ShutIt on the server

– Run the ‘copyserver’ ShutIt script

– Run your copyserver Docker image as a container

Step 1

Install ShutIt as root:

sudo su -
(apt-get update && apt-get install -y python-pip git docker) || (yum update && yum install -y python-pip git docker which)
pip install shutit

The pre-requisites are python-pip, git and docker. The exact names of these in your package manager may vary slightly (eg docker-io or depending on your distro.

You may need to make sure the docker server is running too, eg with ‘systemctl start docker’ or ‘service docker start’.

Step 2

Check out the copyserver script:

git clone

Step 3

Run the copy_server script:

cd shutit_copyserver/bin

There are a couple of prompts – one to correct perms on a config file, and another to ask what docker base image you want to use. Make sure you use one as close to the original server as possible.

Note that this requires a version of docker that has the ‘docker exec’ option.

Step 4

Run the build server:

docker run -ti copyserver /bin/bash

You are now in a practical facsimile of your server within a docker container!

This is not the finished article, so if you need help dockerizing a server, let me know what the problem is, as improvements can still be made.

This post is based on material from Docker in Practice, available on Manning’s Early Access Program. Get 39% off with the code: 39miell


This entry was posted in Uncategorized. Bookmark the permalink.

11 Responses to Convert Any Server to a Docker Container

  1. Manfred von Lauck says:

    “How and Why? Let’s say you have a server that has been lovingly hand-crafted that you *want to containerize.*”

    Where is the “Why” -part? Why should I want to containerize my server? (apart from because I can)

    • Giovanni says:

      Same question here.

      “Containerize my server” is applying the same mentality that was seen when virtual machines came up, but now to containers. It’s extremely inefficient and doesn’t buy you anything. This huge container will sit there unmanaged and it’s now much more of a black box than it was before. IMHO, this is not how containers are meant to be used. They should use minimal images, have only the necessary bits and enable quick builds and deployment of new code. If you are treating a container as a VM, you’re better off staying with the VM.

      • zwischenzugs says:

        I agree on most points; the implication of what you are saying is that the hard part to change is the behaviour – going from mutable servers to immutable rebuilt configurations.

        However, I think that containerizing (and the benefits of a more lightweight disposable environment) can facilitate the move in this area (just as VMs did to a large extent. I’ve seen this happen first hand.

  2. Pingback: Convert a server to a Docker container | 0ddn1x: tricks with *nix

  3. Pingback: Double Shot #1509 | CodangoNet

  4. Pingback: Top 10 links for the week of May 25 - HighOps

  5. It would also be an option to just start a Docker Container with Python and mount the application directory as a data volume inside your container.

    If you need persistent data you can copy the data into a Docker Volume directly. For example “docker run –volumes-from GHOSTDATA -v /srv/http/ghost:/migrate busybox cp /migrate/config.js /ghost-override” This copies local data directly into a busybox container using the docker run command.

  6. Pingback: Docker and CoreOS Friends again! - GilesCope.Ninja

  7. ritesh rekhi says:

    For a FIPS enabled VM, pip install shutit doesn’t work

    root@xxxx:~# pip install shutit
    You are using pip version 7.1.0, however version 8.1.2 is available.
    You should consider upgrading via the ‘pip install –upgrade pip’ command.
    Requirement already satisfied (use –upgrade to upgrade): shutit in /usr/lib/python2.6/site-packages/shutit-0.9.191-py2.6.egg
    Collecting pexpect>=4.0 (from shutit)
    /usr/lib/python2.6/site-packages/pip/_vendor/requests/packages/urllib3/util/ InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see
    Unsupported hash name md5 for package (from
    Downloading pexpect-4.1.0-py2.py3-none-any.whl (54kB)
    100% |████████████████████████████████| 57kB 3.3MB/s
    Traceback (most recent call last):
    File “/usr/lib/python2.6/site-packages/pip/”, line 223, in main
    status =, args)
    File “/usr/lib/python2.6/site-packages/pip/commands/”, line 290, in run
    File “/usr/lib/python2.6/site-packages/pip/req/”, line 334, in prepare_files
    functools.partial(self._prepare_file, finder))
    File “/usr/lib/python2.6/site-packages/pip/req/”, line 321, in _walk_req_to_install
    more_reqs = handler(req_to_install)
    File “/usr/lib/python2.6/site-packages/pip/req/”, line 491, in _prepare_file
    File “/usr/lib/python2.6/site-packages/pip/”, line 825, in unpack_url
    File “/usr/lib/python2.6/site-packages/pip/”, line 673, in unpack_http_url
    from_path, content_type = _download_http_url(link, session, temp_dir)
    File “/usr/lib/python2.6/site-packages/pip/”, line 886, in _download_http_url
    _download_url(resp, link, content_file)
    File “/usr/lib/python2.6/site-packages/pip/”, line 626, in _download_url
    _check_hash(download_hash, link)
    File “/usr/lib/python2.6/site-packages/pip/”, line 489, in _check_hash
    if download_hash.digest_size !=
    AttributeError: ‘NoneType’ object has no attribute ‘digest_size’

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s