Documentation

Build immutable docker images with Nomirun

Docker offers numerous benefits, particularly in software development and deployment. Firstly, it ensures consistency by encapsulating applications and their dependencies into containers, making them portable across environments. This minimizes “it works on my machine” issues. Secondly, Docker accelerates development cycles by enabling quick, reproducible, and isolated testing environments. It enhances scalability, as containers can be easily scaled up or down to meet demand. Using lightweight containers reduces overhead compared to traditional virtual machines, enhancing performance and efficiency. Furthermore, Docker integrates well with CI/CD pipelines, streamlining deployment. Its vast ecosystem and rich community support make it a go-to tool for modern DevOps workflows.

Nomirun CLI offers 2 approaches with Docker images and containers.

1. Run Docker Image with a build process at Runtime

In this method, Docker runs the container with configuration instructions for building application modules during startup. While convenient for dynamic or development environments, this approach is less optimal for production as the Docker image becomes mutable. It may increase container start-up time and risk runtime variations or inconsistency.

You can achieve this behaviour by configuring and running the Nomirun cluster by:

 nomirun cluster configure --cluster-name "MyShopMonolith" --nuget-server-name "Local Folder" --target-format DockerEnvFile
 nomirun cluster start --cluster-name "MyShopMonolith" --host-type Container

This will take pre-build Nomirun host Docker image and configure it to run the hosts and modules in the specified cluster.

Switch --nuget-server-name defines a NuGet Repository, in case above its local NuGet folder (“Local Folder”). Define this with nomirun init command.

2. Pre-build Application Before Dockerization

Here, the application is fully built first, and the compiled files are copied into the Docker image. The resulting container is immutable, ensuring consistency across environments. Since the image contains the pre-built application, it starts faster, is more reliable for production usage, and adheres to best practices in image creation.

  • First you need to configure cluster and specify the --target-format for configuration. In case below we are generating .env file. We will support more formats in the future, depending on the need.
  • Then you can build the cluster, which will build all the hosts in the cluster and its Docker images. At the end of the build process, you also get a docker run command for every host so you can start it instantly.
 nomi cluster configure -c MyShopMonolith --nuget-server-name "Feedz.io" --target-format DockerEnvFile
 nomi cluster build -c MyShopMonolith --host-framework net9.0 --host-type Container --docker-image-tag v1.0

The output of the nomi cluster build command looks like this:

...
Host MyShopApi run command - cd C:\Users\nomi\.nomirun\host\MyShopApi && docker run --rm --name myshopmonolith.myshopapi.app --env-file .env -p
5590:5000 -p 5591:5001 -p 5592:5002 -p 5593:5003 -p 5594:5004 -p 5595:5005 myshopmonolith.myshopapi.app:v1.0
Build completed!

If you have multiple hosts in the cluster, you’ll get a docker image and docker run command for all of them.

You can see the convention of docker image names - CLUSTER_NAME.HOST_NAME.app:TAG.

Docker containers will use the same ports as you used for development, but you can always change then depending on your need. Docker always exposes six ports, 5000, 5001, 5002, 5003, 5004, 5005. Read more about it here.

Now you can re-tag docker images for your registry and push them.

 docker tag myshopmonolith.myshopapi.app:v1.0 mydocker-hub.com/myshopmonolith.myshopapi.app:v1.0 ...
 docker push mydocker-hub.com/myshopmonolith.myshopapi.app:v1.0 ...

Build standalone cluster

You can also build a standalone Nomirun host application. That means CLI will create a ZIP file containing a pre-built host application.

It’s analogous to the approach above - if you have multiple hosts in the cluster, multiple ZIP files will be created.

You can configure and build it like this:

 nomi cluster configure -c MyShopMonolith --nuget-server-name "Feedz.io"
 nomi cluster build -c MyShopMonolith --host-platform win-x64 --host-framework net9.0 --output d:\Nomirun

You need to specify the --host-platform and --output where all the ZIP files are stored.