Skip to content

Building the Docker images

Edwin van Wijk edited this page May 25, 2022 · 5 revisions

In order to run the application you need to take several steps. This description assumes you're developing on a Windows machine using Visual Studio Code and already downloaded or forked and pulled the latest version of the source-code from the repo.

Make sure your have satisfied the Prerequisites.

In the docker-compose.yml file in the root of the solution folder there are some credentials specified for components that need them. These are also used by the different services that use these components (specified in config files): SQL Server login: sa / 8jkGh47hnDw89Haq8LN2, Rabbit MQ login: rabbitmquser / DEBmbwkSrzy9D1T9cJfa

  • Satisfy prerequisites

    • Make sure you have Docker installed and running smoothly on your machine. This sample only uses Linux based containers. Also make sure everything is configured correctly in order to pull Docker images from the public Docker hub.
    • Increase the amount of memory dedicated to Docker to at least 4 GB. You can do this on the Advanced tab of the Docker settings dialog:

  • Open the PitStop solution in Visual Studio Code.

To prevent project-references between projects in the solution, I've published the Infrastructure.Messaging package on NuGet. The NuGet feed is read-only. So if you want to make changes to the InfraStructure package, create a pull request with the necessary changes (don't forget to update the version of the package). I will then push the latest version of the package to NuGet.

  • Build docker images Open up a Powershell window and go to the Pitstop/src folder. Then execute the RebuildAllDockerImages script. This will rebuild all the Docker images for all the projects. Watch the output for any errors. After the images are built, you could check whether they are all there using the docker images command. This should yield something like this:

Volumes
As part of the RebuildAllDockerImages script, two Docker volumes are created. One for the SQL Server data and one for the RabbitMQ data. This ensures that data for these infrastructural components survives restarts of the Containers.

Base images
All the Pitstop docker images are built based on .NET base images:

  • .NET SDK image for building the .NET application
  • .NET runtime image for running Console / Worker apps
  • ASP.NET image for running Web Apps / Web APIs

In order to be able to define the version of the base-images to use in one place and to add custom files that reside outside of the Docker context for each service, a Pitstop specific base-image is created for these .NET base-images. The Docker files for these base-images are situated in the src folder:

  • dotnet-sdk-base-dockerfile
  • dotnet-runtime-base-dockerfile
  • dotnet-aspnet-base-dockerfile

You can change the version of the .NET base-images to use for all the services at once by changing these files.

You can see the commands that create the Pitstop specific base-images in the RebuildAllDockerImages script:

docker build -t pitstop-dotnet-sdk-base:1.0 . -f dotnet-sdk-base-dockerfile
docker build -t pitstop-dotnet-runtime-base:1.0 . -f dotnet-runtime-base-dockerfile
docker build -t pitstop-dotnet-aspnet-base:1.0 . -f dotnet-aspnet-base-dockerfile

In all the Dockerfiles for the services, you can see the Pitstop specific base-images are used. Here's a fragment of the Dockerfile for the AuditlogService:

FROM pitstop-dotnet-sdk-base:1.0 AS build-env

# ...

FROM pitstop-dotnet-runtime-base:1.0

# ...

So make sure you always use the RebuildAllDockerImages script to build the Docker images!!