Urgent.News

What's breaking now, across thousands of outlets.

Tech

How to deploy a dotnet application without a Dockerfile or Docker build process

When deploying a .net application to a docker container you would commonly use a Dockerfile, build the Docker image then push the Docker image to a registry, pull the whole image from the registry again to the server and run the image. There are many benefits in doing it that way, especially in larger production environments. But when you’re just testing, deploying to small production or staging…

Deploying a .NET application to a Docker container without a Dockerfile or Docker build process can be a convenient option, especially for testing, small production, or staging environments. This method eliminates the need to build the entire image, write and manage a Dockerfile, or install Docker on the build machine. Instead, it involves three simple steps to run a .NET application on a Linux Ubuntu server within an Arch Linux Docker container.

First, build your application binaries using the `dotnet publish` command with the `-r linux-musl-x64 -c Release` flags. This will create a portable binary suitable for Linux containers. No Dockerfile or Docker Desktop is required, and your project remains unmodified. On the .NET 10 version, the published binaries will be found in the `bin\Release\net10.0\linux-musl-x64\publish` directory.

Next, copy these binaries to your Linux server, creating a directory to store them. Ensure the binary is executable and adjust the permissions for the log directory if you plan to use one, especially when using a hardened base image like the DHI image. Add the binary directory and optional log directory to your Docker Compose YAML file, specifying the image, volume mounts for the binary and log directories, and the entrypoint to run the application. Remember to include necessary configurations like Docker Hub credentials if using a specific image.

Finally, deploy your application using the `docker stack deploy` command, pointing to your Docker Compose file. This will create and run the Docker container on your server. Updating the application is straightforward—just copy the new binary and rerun the update command. This method allows for quick deployment, easy image swapping, and the ability to edit application settings directly.

Additionally, using Docker secrets with ASP.NET applications can be achieved by adding the `AddKeyPerFile` method in your `Program.cs` file.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

More from Wednesday 16 September →