Building Linux Docker Containers on Windows 10 with Linux Docker Containers

If you already have a Linux-based build system for building out your Docker images, you can still bootstrap building these containers using only Windows 10 and Docker for Windows.

Creating the Build Container

First, you need to build a build container. This should contain whatever tooling you're using to build out images, and the Docker client. Just the client is needed, as the Docker socket will be mounted from the host machine.

Choosing a Base Image

In this example I've chosen to use a CentOS base image and install the development tools package group. This is really just personal preference and/or the tools that you need. Note that using a BusyBox based image like Alpine may not work as desired, as many of the core utilities have missing features.

Installing the Docker Client

Docker provides instructions on installing binaries. You should really only need a client that communicates with the same API version as your host machine (docker version -f '{{.Client.APIVersion}}'). One thing not mentioned in the documentation, is that the domain for release candidate versions is test.docker.com instead of get.docker.com.

Example Dockerfile:

docker
FROM centos:7

# Install Development Tools
RUN yum -y upgrade \
	&& yum -y groupinstall 'Development Tools' \
	&& yum clean all

# Install Docker Binaries
ARG DOCKER_VERSION
RUN DOCKER_SUBDOMAIN=$(echo $DOCKER_VERSION | grep -q rc && echo 'test' || echo 'get') \
	&& DOCKER_PACKAGE="docker-${DOCKER_VERSION}.tgz" \
	&& curl -SsLO "https://${DOCKER_SUBDOMAIN}.docker.com/builds/Linux/x86_64/${DOCKER_PACKAGE}" \
	&& curl -SsLO "https://${DOCKER_SUBDOMAIN}.docker.com/builds/Linux/x86_64/${DOCKER_PACKAGE}.sha256" \
	&& sha256sum -c --status "${DOCKER_PACKAGE}.sha256" \
	&& tar --strip-components=1 -xvzf "${DOCKER_PACKAGE}" -C /usr/local/bin/ \
	&& rm -f "${DOCKER_PACKAGE}"*

Running the Build Container

Finally, you just need to run the build container with the docker socket mounted. On Windows, you can map volumes inside the Docker VM:

-v /var/run/docker.sock:/var/run/docker.sock