Reorganize the Dockerfiles, to share code.
Also add gcc 6 to the 16.04 image and Bazel to the 15.10 image.
diff --git a/extras/dockerfiles/Dockerfile.ubuntu-14.04 b/extras/dockerfiles/Dockerfile.ubuntu-14.04
new file mode 100644
index 0000000..42acb44
--- /dev/null
+++ b/extras/dockerfiles/Dockerfile.ubuntu-14.04
@@ -0,0 +1,9 @@
+FROM ubuntu:14.04
+MAINTAINER Marco Poletti <poletti.marco@gmail.com>
+
+COPY ubuntu-14.04_custom.list /etc/apt/sources.list.d/
+COPY common_install.sh common_cleanup.sh ubuntu-14.04_install.sh /
+
+RUN bash -x /common_install.sh && \
+    bash -x /ubuntu-14.04_install.sh && \
+    bash -x /common_cleanup.sh
diff --git a/extras/dockerfiles/Dockerfile.ubuntu-15.10 b/extras/dockerfiles/Dockerfile.ubuntu-15.10
new file mode 100644
index 0000000..a7ce4b3
--- /dev/null
+++ b/extras/dockerfiles/Dockerfile.ubuntu-15.10
@@ -0,0 +1,9 @@
+FROM ubuntu:15.10
+MAINTAINER Marco Poletti <poletti.marco@gmail.com>
+
+COPY ubuntu-15.10_custom.list /etc/apt/sources.list.d/
+COPY common_install.sh common_cleanup.sh ubuntu-15.10_install.sh /
+
+RUN bash -x /common_install.sh && \
+    bash -x /ubuntu-15.10_install.sh && \
+    bash -x /common_cleanup.sh
diff --git a/extras/dockerfiles/Dockerfile.ubuntu-16.04 b/extras/dockerfiles/Dockerfile.ubuntu-16.04
new file mode 100644
index 0000000..b53b883
--- /dev/null
+++ b/extras/dockerfiles/Dockerfile.ubuntu-16.04
@@ -0,0 +1,9 @@
+FROM ubuntu:16.04
+MAINTAINER Marco Poletti <poletti.marco@gmail.com>
+
+COPY ubuntu-16.04_custom.list /etc/apt/sources.list.d/
+COPY common_install.sh common_cleanup.sh ubuntu-16.04_install.sh /
+
+RUN bash -x /common_install.sh && \
+    bash -x /ubuntu-16.04_install.sh && \
+    bash -x /common_cleanup.sh
diff --git a/extras/dockerfiles/common_cleanup.sh b/extras/dockerfiles/common_cleanup.sh
new file mode 100644
index 0000000..da94e10
--- /dev/null
+++ b/extras/dockerfiles/common_cleanup.sh
@@ -0,0 +1,13 @@
+#!/bin/bash
+
+set -e
+
+# Strip some binaries that aren't already stripped, to save space.
+for f in $(find /usr/lib/ /usr/bin -type f); do if file "$f" | fgrep 'executable' | fgrep -q 'stripped'; then strip --strip-unneeded $f; fi; done
+
+# This was only needed above, we don't need it in the final image.
+apt-get remove -y wget file
+
+# Remove temporary files, to save space.
+apt-get clean
+rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
diff --git a/extras/dockerfiles/common_install.sh b/extras/dockerfiles/common_install.sh
new file mode 100644
index 0000000..3da1d22
--- /dev/null
+++ b/extras/dockerfiles/common_install.sh
@@ -0,0 +1,26 @@
+#!/bin/bash
+
+set -e
+
+apt-get update -qq
+apt-get install -y --no-install-recommends wget
+
+wget -O - http://llvm.org/apt/llvm-snapshot.gpg.key | apt-key add -
+
+# 1E9377A2BA9EF27F is the key for the ubuntu-toolchain-r PPA.
+apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 1E9377A2BA9EF27F
+
+apt-get update -qq
+apt-get install -y --no-install-recommends \
+    file \
+    valgrind \
+    make \
+    cmake \
+    g++-4.8 \
+    g++-4.9 \
+    g++-5 \
+    clang-3.5 \
+    clang-3.6 \
+    clang-3.7 \
+    clang-3.8 \
+    libc++-dev
diff --git a/extras/dockerfiles/ubuntu-14.04/Dockerfile b/extras/dockerfiles/ubuntu-14.04/Dockerfile
deleted file mode 100644
index eacbbbe..0000000
--- a/extras/dockerfiles/ubuntu-14.04/Dockerfile
+++ /dev/null
@@ -1,23 +0,0 @@
-FROM ubuntu:14.04
-MAINTAINER Marco Poletti <poletti.marco@gmail.com>
-
-COPY custom.list /etc/apt/sources.list.d/
-
-# 1E9377A2BA9EF27F is the key for the ubuntu-toolchain-r PPA.
-RUN apt-get install -y --no-install-recommends wget && \
-    wget -O - http://llvm.org/apt/llvm-snapshot.gpg.key | apt-key add - && \
-    apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 1E9377A2BA9EF27F && \
-    apt-get update -qq && \
-    apt-get install -y --no-install-recommends \
-        valgrind \
-        make \
-        cmake \
-        g++-4.8 \
-        g++-4.9 \
-        g++-5 \
-        clang-3.5 \
-        clang-3.6 \
-        clang-3.7 \
-        clang-3.8 \
-        libc++-dev && \
-    find /usr/lib /usr/bin -type f | while read f; do if file "$f" | fgrep executable | fgrep -q "not stripped"; then strip "$f"; fi; done
diff --git a/extras/dockerfiles/ubuntu-14.04/custom.list b/extras/dockerfiles/ubuntu-14.04_custom.list
similarity index 100%
rename from extras/dockerfiles/ubuntu-14.04/custom.list
rename to extras/dockerfiles/ubuntu-14.04_custom.list
diff --git a/extras/dockerfiles/ubuntu-14.04_install.sh b/extras/dockerfiles/ubuntu-14.04_install.sh
new file mode 100644
index 0000000..d9628ae
--- /dev/null
+++ b/extras/dockerfiles/ubuntu-14.04_install.sh
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+set -e
diff --git a/extras/dockerfiles/ubuntu-15.10/Dockerfile b/extras/dockerfiles/ubuntu-15.10/Dockerfile
deleted file mode 100644
index 1e6348a..0000000
--- a/extras/dockerfiles/ubuntu-15.10/Dockerfile
+++ /dev/null
@@ -1,23 +0,0 @@
-FROM ubuntu:15.10
-MAINTAINER Marco Poletti <poletti.marco@gmail.com>
-
-COPY custom.list /etc/apt/sources.list.d/
-
-# 1E9377A2BA9EF27F is the key for the ubuntu-toolchain-r PPA.
-RUN apt-get install -y --no-install-recommends wget && \
-    wget -O - http://llvm.org/apt/llvm-snapshot.gpg.key | apt-key add - && \
-    apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 1E9377A2BA9EF27F && \
-    apt-get update -qq && \
-    apt-get install -y --no-install-recommends \
-        valgrind \
-        make \
-        cmake \
-        g++-4.8 \
-        g++-4.9 \
-        g++-5 \
-        clang-3.5 \
-        clang-3.6 \
-        clang-3.7 \
-        clang-3.8 \
-        libc++-dev && \
-    find /usr/lib /usr/bin -type f | while read f; do if file "$f" | fgrep executable | fgrep -q "not stripped"; then strip "$f"; fi; done
diff --git a/extras/dockerfiles/ubuntu-15.10/custom.list b/extras/dockerfiles/ubuntu-15.10_custom.list
similarity index 100%
rename from extras/dockerfiles/ubuntu-15.10/custom.list
rename to extras/dockerfiles/ubuntu-15.10_custom.list
diff --git a/extras/dockerfiles/ubuntu-15.10_install.sh b/extras/dockerfiles/ubuntu-15.10_install.sh
new file mode 100644
index 0000000..6a2e3ef
--- /dev/null
+++ b/extras/dockerfiles/ubuntu-15.10_install.sh
@@ -0,0 +1,17 @@
+#!/bin/bash
+
+set -e
+
+# For Bazel
+apt-get install -y --no-install-recommends \
+    openjdk-8-jdk \
+    pkg-config \
+    zip \
+    g++ \
+    zlib1g-dev \
+    unzip
+# TODO: keep this version (reasonably) up to date.
+BAZEL_VERSION=0.2.2b
+wget https://github.com/bazelbuild/bazel/releases/download/${BAZEL_VERSION}/bazel-${BAZEL_VERSION}-installer-linux-x86_64.sh
+bash bazel-${BAZEL_VERSION}-installer-linux-x86_64.sh
+rm bazel-${BAZEL_VERSION}-installer-linux-x86_64.sh
diff --git a/extras/dockerfiles/ubuntu-16.04/Dockerfile b/extras/dockerfiles/ubuntu-16.04/Dockerfile
deleted file mode 100644
index 920e820..0000000
--- a/extras/dockerfiles/ubuntu-16.04/Dockerfile
+++ /dev/null
@@ -1,23 +0,0 @@
-FROM ubuntu:16.04
-MAINTAINER Marco Poletti <poletti.marco@gmail.com>
-
-COPY custom.list /etc/apt/sources.list.d/
-
-# 1E9377A2BA9EF27F is the key for the ubuntu-toolchain-r PPA.
-RUN apt-get install -y --no-install-recommends wget && \
-    wget -O - http://llvm.org/apt/llvm-snapshot.gpg.key | apt-key add - && \
-    apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 1E9377A2BA9EF27F && \
-    apt-get update -qq && \
-    apt-get install -y --no-install-recommends \
-        valgrind \
-        make \
-        cmake \
-        g++-4.8 \
-        g++-4.9 \
-        g++-5 \
-        clang-3.5 \
-        clang-3.6 \
-        clang-3.7 \
-        clang-3.8 \
-        libc++-dev && \
-    find /usr/lib /usr/bin -type f | while read f; do if file "$f" | fgrep executable | fgrep -q "not stripped"; then strip "$f"; fi; done
diff --git a/extras/dockerfiles/ubuntu-16.04/custom.list b/extras/dockerfiles/ubuntu-16.04_custom.list
similarity index 100%
rename from extras/dockerfiles/ubuntu-16.04/custom.list
rename to extras/dockerfiles/ubuntu-16.04_custom.list
diff --git a/extras/dockerfiles/ubuntu-16.04_install.sh b/extras/dockerfiles/ubuntu-16.04_install.sh
new file mode 100644
index 0000000..7e370f1
--- /dev/null
+++ b/extras/dockerfiles/ubuntu-16.04_install.sh
@@ -0,0 +1,6 @@
+#!/bin/bash
+
+set -e
+
+apt-get install -y --no-install-recommends \
+    g++-6