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 "GitHub"
 nomirun cluster generate --cluster-name MyShopMonolith --target-format DockerEnvFile
 nomirun cluster start --cluster-name MyShopMonolith --host-type Container

This will take a 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 (“GitHub”). 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 you can use nomi cluster generate and specify the --target-format for the configuration output format. In the 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"
 nomi cluster generate -c MyShopMonolith --target-format DockerEnvFile
 nomi cluster build -c MyShopMonolith --host-type Container --docker-image-tag v1.0

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

...
Container information about cluster host saved to:
C:\Users\MyUser\.nomirun\clusters\SolarPlatformKubernetes\container-custer-info-SolarPlatformKubernetes-v1.txt

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

You can see the convention of docker image names - 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 ...

3. 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 --output d:\Nomirun

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

4. Pre-build only a single host within the cluster

This is particularly useful when you want to build a single host from the CI/CD pipeline.

To build container image for a single host, you can use the following command:

 nomi cluster build-host -c MyShopMonolith -h BillingHost --host-type Container --docker-image-tag v1.0

To build a standalone host, you can use the following command:

 nomi cluster build-host -c MyShopMonolith -h BillingHost --host-type Standalone -o c:\hosts