The dotnet-mono-dockerclient docker image contains:
- .NET Core base image
- A docker client
This make it a great image to run automated build of .NET Core projects using Cake (thus that depends on mono) and that generate docker images.
Since this image contains a docker client, when you start a container based on
dotnet-mono-dockerclient, it will be possible to run
docker commands from within your container. This is what's called by some docker-in-docker. With the proper
docker run options, the docker client that it contains will be able to connect to a docker server running outside of the container. Two options are possible to specify the docker server to use:
- Set the
DOCKER_HOSTenvironment variable when calling
docker run -e "DOCKER_HOST=NAME_OF_HOST_RUNNING_DOCKER_SERVER"
- Use the
-v /var/run/docker.sock:/var/run/docker.sockoption of
docker runas described here. This is my prefered option since it does not require the docker server running on your build machine to accept connections from outside of the server, thus keeping your server secure.
Here is a typical example of how to use this capability:
- Start a container where you mount your build script (
your_build.sh). Note the two -v options. This assumes that you have a script named
your_build.shthat exists at the root of your git repository.
docker run -i --rm \ -v /var/run/docker.sock:/var/run/docker.sock \ -v $(pwd):/git \ -w /git \ mabead/dotnet-mono-dockerclient:PROPER_TAG \ ./your_build.sh
- From within
your_build.sh, you can then execute other docker commands that will be executed on the docker server running on your host. For example, you can build new containers from within your build container!