Due to reasons that don't bear going into, I recently needed to run python2.6 in a docker container. After a ton of problems and stack overflow questions with no good answers, I finally figured it out.

I'm a super big fan of Alpine Linux for docker containers, specifically gliderlabs/docker-alpine, which is a minimal version of Alpine tailor-built for tiny docker images.

I started with the official Python 2.7 on alpine docker image. If you replace the

ENV PYTHON_VERSION 2.7.13  

with

ENV PYTHON_VERSION 2.6.9  

You'll quickly find out that the GPG key isn't the same one used before. Just for grins, let's remove the gpg-related stuff to get working:

--- Dockerfile.orig     2017-01-19 20:02:16.000000000 -0500
+++ Dockerfile  2017-01-19 20:02:29.000000000 -0500
@@ -25,11 +25,6 @@
                xz \
        \
        && wget -O python.tar.xz "https://www.python.org/ftp/python/${PYTHON_VERSION%%[a-z]*}/Python-$PYTHON_VERSION.tar.xz" \
-       && wget -O python.tar.xz.asc "https://www.python.org/ftp/python/${PYTHON_VERSION%%[a-z]*}/Python-$PYTHON_VERSION.tar.xz.asc" \
-       && export GNUPGHOME="$(mktemp -d)" \
-       && gpg --keyserver ha.pool.sks-keyservers.net --recv-keys "$GPG_KEY" \
-       && gpg --batch --verify python.tar.xz.asc python.tar.xz \
-       && rm -r "$GNUPGHOME" python.tar.xz.asc \
        && mkdir -p /usr/src/python \
        && tar -xJC /usr/src/python --strip-components=1 -f python.tar.xz \
        && rm python.tar.xz \

Okay, let's run again! sudo docker build .

Here is where we quickly start running into the same problems that I saw on this Stackoverflow question

./Modules/posixmodule.c:6173:1: error: conflicting types for 'posix_close'
 posix_close(PyObject *self, PyObject *args)
 ^
In file included from Include/Python.h:44:0,  
                 from ./Modules/posixmodule.c:30:
/usr/include/unistd.h:38:5: note: previous declaration of 'posix_close' was here
 int posix_close(int, int);
     ^
Makefile:1234: recipe for target 'Modules/posixmodule.o' failed  

Doing some quick googling, we come across a very similar issue on bugs.python.org, issue 20694. A patch is provided in that issue, which we doesn't work on this version of Python as the lines have since changed, making the patch invalid. Luckily, it's not that hard to make a patch. All we need to do is find these two lines:

-posix_close(PyObject *self, PyObject *args)
+posix_closex(PyObject *self, PyObject *args)

and

-    {"close",           posix_close, METH_VARARGS, posix_close__doc__},
+    {"close",           posix_closex, METH_VARARGS, posix_close__doc__},

Which have not changed, they're just on new line numbers. After making our changes and running the command to get a patch on linux, diff -Naur ./Modules/posixmodule.c.orig ./Modules/posixmodule.c > python-2.6-posix-module.patch, which generates this new patch file:

--- ./Modules/posixmodule.c.orig
+++ ./Modules/posixmodule.c
@@ -3896,7 +3896,7 @@
 #endif
     gid_t grouplist[MAX_GROUPS];

-    /* On MacOSX getgroups(2) can return more than MAX_GROUPS results
+    /* On MacOSX getgroups(2) can return more than MAX_GROUPS results
      * This is a helper variable to store the intermediate result when
      * that happens.
      *
@@ -6357,7 +6357,7 @@
 Close a file descriptor (for low level IO).");

 static PyObject *
-posix_close(PyObject *self, PyObject *args)
+posix_closex(PyObject *self, PyObject *args)
 {
     int fd, res;
     if (!PyArg_ParseTuple(args, "i:close", &fd))
@@ -8602,7 +8602,7 @@
     {"tcsetpgrp",       posix_tcsetpgrp, METH_VARARGS, posix_tcsetpgrp__doc__},
 #endif /* HAVE_TCSETPGRP */
     {"open",            posix_open, METH_VARARGS, posix_open__doc__},
-    {"close",           posix_close, METH_VARARGS, posix_close__doc__},
+    {"close",           posix_closex, METH_VARARGS, posix_close__doc__},
     {"closerange",      posix_closerange, METH_VARARGS, posix_closerange__doc__},
     {"dup",             posix_dup, METH_VARARGS, posix_dup__doc__},
     {"dup2",            posix_dup2, METH_VARARGS, posix_dup2__doc__},

All we have to do then is throw in a couple of commands to copy our patch file into Docker and run them, and we have Python2.6 running in Docker!

You can see the final Dockerfile and patch file here: https://gist.github.com/cwill747/722f41d8807c3b41a1e417849634cfe5