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


15 thoughts on “Convert Any Server to a Docker Container

  1. “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)

    1. 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.

      1. 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. 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.

  3. 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’

  4. Hi zwischenzugs,

    I am trying to run ./ But getting the below error. I am running it in an amazonlinux system (yum). Is there an issue due to this OS? Please help.

    ShutIt version: 1.0.27
    Linux ip-10-0-2-39 3.14.42-31.38.amzn1.x86_64 #1 SMP Wed May 13 20:33:05 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux

    2017-10-04 11:50:18,809 INFO: Installing package: python-pip
    Traceback (most recent call last):
    File “/usr/local/bin/shutit”, line 11, in
    File “/usr/local/lib/python2.7/site-packages/”, line 67, in main
    File “/usr/local/lib/python2.7/site-packages/”, line 3942, in setup_shutit_obj
    File “/usr/local/lib/python2.7/site-packages/”, line 4181, in do_build
    File “/usr/local/lib/python2.7/site-packages/”, line 4123, in build_module
    if not
    File “/usr/local/lib/python2.7/site-packages/”, line 59, in wrapper
    ret = func(self, shutit)
    File “/opt/shutit_copyserver/”, line 66, in build
    File “/usr/local/lib/python2.7/site-packages/”, line 1798, in install
    File “/usr/local/lib/python2.7/site-packages/”, line 1393, in install
    package = package_map.map_packages(package, self.current_environment.install_type)
    File “/usr/local/lib/python2.7/site-packages/”, line 108, in map_packages
    res = res + ‘ ‘ + map_package(package,install_type)
    TypeError: cannot concatenate ‘str’ and ‘function’ objects

  5. At Dockerfile I see a git clone pointing to a repo that I should create. What I should upload to this repo? files generated by the script? which files?

Leave a Reply to ritesh rekhi Cancel 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 )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.