Creating an own docker image is not very difficult - I mean it’s pretty well documented here. The challenges actually come when you want to create an image which is not just a simple example but something useful for your needs. Still mainly working at a company with Microsoft focus, I am currently helping a project to get it’s .Net and ASP application running in a container. For this I actually need a container with .Net as well as IIS with some extensions. As I did not find any image in DockerHub, I decided to create my own image. I could base it on amicrosoft/windowsservercore image or microsoft/dotnet-framework. I choose later and will install the necessary features via DSIM, the Deployment Image Servicing and Management tool.
Creating an image
So the first step is to create the Dockerfile, which in my case looks like this:
Once created, I simply run docker build. Unfortunately in my case the building of the image struggled at the point when the feature “WCF-MSMQ-Activation45” should be installed:
So what do now? The log file which I am supposed to consult is within the image, so how can access it. Well understanding the build process makes it obvious, simple run an interactive container with the image created so far…
Now that we know the image - it currently has no name but only and image id - we can launch a container to examine the log file.
In order to continue I will simply remove the installation of “WCF-MSMQ-Activation45” feature for now, cause it seems a bit more tricky to solve and it may be actually even not required in the end to run the final application. After updating the Dockerfile, we simply call docker build again. This will not create all from scratch again but relies on the cached data so the build process actually continues where left off and install the missing features
Use your image
Once your image is build, you can use it and run containers based on it. Keep in mind, the image is currently locally available only.
As I did not provide any tag when calling docker build - i.e. use docker build -t - I would have to use the image ID. Therefore I will first tag the image appropriately - anyway something I need to do before pushing the image to the registry.
So now I can simply start a container using my new image
Publish and Image
Once the image is created it would make sense to publish it to a registry - in this example I use Dockerhub. It is simple, just follow the steps describe in the Docker Wiki. First I have to create a repository:
After your repository is created - assuming you are already logged in to Dockerhub - simply push the image to the registry. As windows images are usually very big (see above) it may take some time:
Once the image is uploaded to the registry it is ready to be used by others.
This is definitely not the final image as I still have to debug the failing installation of MSMQ and there my be other components required to get the final application running within a container. But with this image as a basis I actually save a lot of time to have my base container to work with.