Overview

After we learned a little bit a docker and containers, let's use docker for what it was meant to :) I have created a simple HTTP server which listens on port: 1234

Source code you can see in my Git

Packaging application in image, we call dockerize and it is done pretty simle.

Steps

Firstly, you need a Dockerfile in the place of your project. Since my project is on C#.NET Core and assuming your application is called: HttpServerDemo.dll, I have used the following Dockerfile:

Dockerfile

Now, let's go through the steps:

Workdir - The workdir on the container which will be used.

FROM - The external resources which will be used.

COPY & RUN - These are self explanatory I hope.

You have to verify you have docker at least 17.05 or newer. My current one is 19.03:

Build

The building is also done fairy simple.

You can list the images as follows:

Start

Once the image has been built, you can start the container using that image:

Finally, you can check the container:

Upload in docker hub

Docker hub is the default registry for docker images. You can upload your image there if you want, bare in mind that it will be public.

Login

Package

Push

Now you can also download this simple web from your docker hub or list it as follows:

Troubleshooting

You can have the following error:

Nuget Issue

In that case, either:

Delete the “obj” and “bin” folders from the directory

Add a command to the “Dockerfile” to not upload these to the container as follows:

Edit Dockerfile