# Deploying ASP.NET Core Web Applications to Docker

> TX Text Control .NET Server can be used to create Web APIs to create documents in ASP.NET Core. This tutorial shows how to deploy these applications using Docker.

> **Note:** This article is outdated and may no longer be accurate.

- **Author:** Bjoern Meyer
- **Published:** 2020-06-23
- **Modified:** 2025-11-16
- **Description:** This tutorial shows how to deploy TX Text Control .NET Server within ASP.NET Core Web Applications to Docker.
- **7 min read** (1246 words)
- **Tags:**
  - ASP.NET Core
  - Docker
  - .NET Core
  - Web API
- **Web URL:** https://www.textcontrol.com/blog/2020/06/23/deploying-an-aspnet-core-web-applications-to-docker/
- **LLMs URL:** https://www.textcontrol.com/blog/2020/06/23/deploying-an-aspnet-core-web-applications-to-docker/llms.txt
- **LLMs-Full URL:** https://www.textcontrol.com/blog/2020/06/23/deploying-an-aspnet-core-web-applications-to-docker/llms-full.txt

---

[TX Text Control .NET Server](https://www.textcontrol.com/product/tx-text-control-dotnet-server/) can be used to create powerful document processing Web APIs in ASP.NET Core Web Applications. This tutorial shows how to deploy these applications to Docker.

### Creating the Application

Create a new ASP.NET Core Web Application by following this tutorial in our documentation:

[ASP.NET Core Web Applications](https://docs.textcontrol.com/textcontrol/asp-dotnet/article.aspnet.dotnetcore.htm)

After following these tutorial steps, you will have an MVC project framework that can utilize TX Text Control to create documents.

### Adding a Web API

In the next step, a simple Web API endpoint is created that converts HTML input to PDF and returns a PDF document.

1. In the *Solution Explorer*, right-click *Controllers* and choose *Add -> Controller* from the context menu. In the opened dialog, select *API Controller - Empty* and confirm with *Add*.
    
    ![Creating the Web API](https://s1-www.textcontrol.com/assets/dist/blog/2020/06/23/a/assets/visualstudio_1.webp "Creating the Web API")
2. Name the controller *DocumentController* and confirm with *Add*.
3. Add the following code to the newly created controller:
    
    ```
    [Route("api/[controller]")]
    [ApiController]
    public class DocumentController : ControllerBase
    {
        [HttpGet]
        [Route("CreatePdf")]
        public ActionResult<string> CreatePdf(string Html)
        {
            using (TXTextControl.ServerTextControl tx = 
              new TXTextControl.ServerTextControl())
            {
                byte[] data;
    
                tx.Create();
                // load the Html content
                tx.Load(Html, TXTextControl.StringStreamType.HTMLFormat);
                // save the document as PDF
                tx.Save(out data, TXTextControl.BinaryStreamType.AdobePDF);
    
                return Convert.ToBase64String(data); // return PDF as base64 string
            }
        }
    }
    ```
4. Start the application and navigate to the endpoint directly to test the functionality. Navigate to (replace the port number with the port number of your application):
    
    *https://localhost:5001/api/document/createpdf?Html=Test*
    
    It should return a long base64 encoded string which is essentially a PDF with the word *Test*. If you see a long base64 encoded string, the Web API works.

### Creating the Dockerfile

A Docker container image is a lightweight, standalone, executable package of software that includes everything needed to run an application: code, runtime, system tools, system libraries and settings.

A Docker image is created automatically based on a Dockerfile by reading the instructions. The following steps are required to prepare a build process:

1. Create a new folder named *docker-test* that contains the following sub-folders and files:
    
    
    - Folder named *app*
    - A text file named *Dockerfile* (no extension)
2. In Visual Studio with the application opened that should be deployed, right-click the project in the *Solution Explorer* and choose *Publish*.
    
    In the opened page *Publish*, click the *Start* button to open the *Pick a publish target* dialog. Select *Folder* as the target:
    
    ![Creating the Web API](https://s1-www.textcontrol.com/assets/dist/blog/2020/06/23/a/assets/visualstudio_3.webp "Creating the Web API")
3. Click the *Advanced...* link to open the *AdvancedSettings* dialog. Make sure to select *Framework-Dependent* as the *Deployment Mode* and *win-x64* as the *Target Runtime*:
    
    ![Creating the Web API](https://s1-www.textcontrol.com/assets/dist/blog/2020/06/23/a/assets/visualstudio_4.webp "Creating the Web API")
    
    Confirm with *Save*. Close the *Pick a publish target* dialog by clicking the *Create Profile* button.
4. Click *Publish* to publish your application. Note the location of the publish folder or click the ![Creating the Web API](https://s1-www.textcontrol.com/assets/dist/blog/2020/06/23/a/assets/copy.webp "Creating the Web API") icon to copy the path to the clipboard.
    
    ![Creating the Web API](https://s1-www.textcontrol.com/assets/dist/blog/2020/06/23/a/assets/visualstudio_5.webp "Creating the Web API")
5. Copy the content of the *publish* folder to the newly created *app* folder from step 1.
6. Open the *Dockerfile* in a text editor such as Visual Studio Code. The Dockerfile script creates a Windows Server container with all requirements including .NET Core run-times and Visual C++ Redistributables.
    
    There are two ways to deploy the application in Docker:
    
    
    - Using IIS
    - Without IIS
    
    Continue this tutorial with the desired approach.
    
    #### Using IIS
    
    Copy the following code to your *Dockerfile*:
    
    ```
    # https://hub.docker.com/_/microsoft-windows-servercore
    # "ltsc2016" to get fonts installed
    # Server Core 2019 is shipped without fonts
    
    FROM mcr.microsoft.com/windows/servercore:ltsc2016
    
    # Copy the application from folder "app" to "C:\app" on container machine
    
    COPY app/ /app
    
    SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]
    
    # Install IIS
    
    RUN Enable-WindowsOptionalFeature -Online -FeatureName IIS-WebServerRole; \
    	Enable-WindowsOptionalFeature -Online -FeatureName IIS-WebServer; \
    	Enable-WindowsOptionalFeature -Online -FeatureName IIS-CommonHttpFeatures
    
    # Download and install Visual C++ Redistributable Packages for Visual Studio 2013
    
    RUN Invoke-WebRequest -OutFile vc_redist.x64.exe https://download.microsoft.com/download/2/E/6/2E61CFA4-993B-4DD4-91DA-3737CD5CD6E3/vcredist_x64.exe; \
    	Start-Process "vc_redist.x64.exe" -ArgumentList "/passive" -wait -Passthru; \
    	del vc_redist.x64.exe
    
    # Install ASP.NET Core Runtime
    # Checksum and direct link from: https://dotnet.microsoft.com/download/dotnet-core/thank-you/runtime-aspnetcore-3.1.5-windows-hosting-bundle-installer
    
    RUN Invoke-WebRequest -OutFile dotnet-hosting-3.1.0-win.exe https://download.visualstudio.microsoft.com/download/pr/fa3f472e-f47f-4ef5-8242-d3438dd59b42/9b2d9d4eecb33fe98060fd2a2cb01dcd/dotnet-hosting-3.1.0-win.exe; \
    	Start-Process "dotnet-hosting-3.1.0-win.exe" -ArgumentList "/passive" -wait -Passthru; \
    	Remove-Item -Force dotnet-hosting-3.1.0-win.exe
    
    # Create a new IIS ApplicationPool
    	
    RUN [string]$appPoolName = 'myAppPool'; \
    	New-WebAppPool $appPoolName; \
    	Import-Module WebAdministration; \
    	$appPool = Get-Item IIS:\AppPools\$appPoolName; \
    	$appPool.managedRuntimeVersion = ''; \
    	$appPool | set-item
    
    RUN [string]$appPoolName = 'myAppPool'; \
    	[string]$appName = 'myDotnetCoreApp'; \
    	New-WebApplication -Name $appName -Site 'Default Web Site' -PhysicalPath C:\app -ApplicationPool $appPoolName
    ```
    
    #### Without IIS
    
    Copy the following code to your *Dockerfile*:
    
    ```
    # https://hub.docker.com/_/microsoft-windows-servercore
    # "ltsc2016" to get fonts installed
    # Server Core 2019 is shipped without fonts
    
    FROM mcr.microsoft.com/windows/servercore:ltsc2016
    
    # Copy the application from folder "app" to "C:\app" on container machine
    
    COPY app/ /app
    
    SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]
    
    # Download and install Visual C++ Redistributable Packages for Visual Studio 2013
    
    RUN Invoke-WebRequest -OutFile vc_redist.x64.exe https://download.microsoft.com/download/2/E/6/2E61CFA4-993B-4DD4-91DA-3737CD5CD6E3/vcredist_x64.exe; \
    	Start-Process "vc_redist.x64.exe" -ArgumentList "/passive" -wait -Passthru; \
    	del vc_redist.x64.exe
    
    # Install ASP.NET Core Runtime
    # Checksum and direct link from: https://dotnet.microsoft.com/download/dotnet-core/thank-you/runtime-aspnetcore-3.1.5-windows-hosting-bundle-installer
    
    RUN Invoke-WebRequest -OutFile dotnet-hosting-3.1.0-win.exe https://download.visualstudio.microsoft.com/download/pr/fa3f472e-f47f-4ef5-8242-d3438dd59b42/9b2d9d4eecb33fe98060fd2a2cb01dcd/dotnet-hosting-3.1.0-win.exe; \
    	Start-Process "dotnet-hosting-3.1.0-win.exe" -ArgumentList "/passive" -wait -Passthru; \
    	Remove-Item -Force dotnet-hosting-3.1.0-win.exe
    
    WORKDIR /app
    EXPOSE 80
    
    ENTRYPOINT ["dotnet", "myDotnetCoreApp.dll"]
    ```

### Creating the Docker Image

In order to create the image, use the following commands:

1. Assume that you have installed [Docker for Windows](https://docs.docker.com/docker-for-windows/), open a PowerShell command window with explicit administrator rights and change to the directory where you created the folder *docker-test*.
    
    ![Creating the Web API](https://s1-www.textcontrol.com/assets/dist/blog/2020/06/23/a/assets/ps_1.webp "Creating the Web API")
2. Type in the following command to build the Docker image based on the *Dockerfile* in the same directory:
    
    ```
    docker build -t txcore .
    ```
    
    ![Creating the Web API](https://s1-www.textcontrol.com/assets/dist/blog/2020/06/23/a/assets/ps_2.webp "Creating the Web API")

### Running the Docker Container

1. Depending on the *Dockerfile* you used in step 6, start the container with one of the following commands:
    
    #### Using IIS
    
    ```
    docker run -it --rm -p 5000:80 --name aspnetcore_sample txcore
    ```
    
    #### Without IIS
    
    ```
    docker run -it --rm -p 5000:80 -e ASPNETCORE_URLS=http://+:80 --name aspnetcore_sample txcore
    ```

In the Docker Dashboard, you can see the running container listening on port 5000:

![Creating the Web API](https://s1-www.textcontrol.com/assets/dist/blog/2020/06/23/a/assets/docker.webp "Creating the Web API")

Open a browser and navigate to *http://localhost:5000* to see your deployed web application.

---

## About Bjoern Meyer

As CEO, Bjoern is the visionary behind our strategic direction and business development, bridging the gap between our customers and engineering teams. His deep passion for coding and web technologies drives the creation of innovative products. If you're at a tech conference, be sure to stop by our booth - you'll most likely meet Bjoern in person. With an advanced graduate degree (Dipl. Inf.) in Computer Science, specializing in AI, from the University of Bremen, Bjoern brings significant expertise to his role. In his spare time, Bjoern enjoys running, paragliding, mountain biking, and playing the piano.

- [LinkedIn](https://www.linkedin.com/in/bjoernmeyer/)
- [X](https://x.com/txbjoern)
- [GitHub](https://github.com/bjoerntx)

---

## Related Posts

- [Announcing the Official DS Server Docker Image on Docker Hub](https://www.textcontrol.com/blog/2025/05/02/announcing-the-official-ds-server-docker-image-on-docker-hub/llms.txt)
- [Using a Private NuGet Feed to Build and Restore .NET Apps for Docker Deployment](https://www.textcontrol.com/blog/2025/04/11/using-a-private-nuget-feed-to-build-and-restore-dotnet-apps-for-docker-deployment/llms.txt)
- [Deploying the TX Text Control Document Editor Backend Web Server in Docker](https://www.textcontrol.com/blog/2025/04/10/deploying-the-tx-text-control-document-editor-backend-web-server-in-docker/llms.txt)
- [Using TX Text Control with Ultra-Minimal Chiseled Linux Containers](https://www.textcontrol.com/blog/2025/03/12/using-tx-text-control-with-ultra-minimal-chiseled-linux-containers/llms.txt)
- [Getting Started: Document Editor with ASP.NET Core and Docker Support with Linux Containers](https://www.textcontrol.com/blog/2025/03/12/getting-started-document-editor-with-asp-net-core-and-docker-support-with-linux-containers/llms.txt)
- [Why an Unlimited Runtime License (OEM) for TX Text Control is Perfect for Cloud Deployments](https://www.textcontrol.com/blog/2025/01/08/why-an-unlimited-runtime-license-oem-for-tx-text-control-is-perfect-for-cloud-deployments/llms.txt)
- [Designing a MailMerge Web API Endpoint with ASP.NET Core in C#](https://www.textcontrol.com/blog/2024/07/12/designing-a-mailmerge-web-api-endpoint-with-asp-net-core-in-c-sharp/llms.txt)
- [Asynchronous Loading and Saving in Angular Document Editor with an ASP.NET Core Web API](https://www.textcontrol.com/blog/2024/03/21/asynchronous-loading-and-saving-in-angular-document-editor-with-an-asp-net-core-web-api/llms.txt)
- [ASP.NET Core: Deploying the TX Text Control 32.0 SP2 Document Editor to Linux](https://www.textcontrol.com/blog/2024/01/22/deploying-tx-text-control-to-linux/llms.txt)
- [Deploying an ASP.NET Core Web App to Azure App Services](https://www.textcontrol.com/blog/2023/09/23/deploying-an-aspnet-core-web-app-to-azure-app-services/llms.txt)
- [Deploying an ASP.NET Core Web App with Docker](https://www.textcontrol.com/blog/2023/09/23/deploying-an-aspnet-core-web-app-with-docker/llms.txt)
- [Document Editor Deployment with Docker and Windows Server Core 2019 and 2022 including Fonts](https://www.textcontrol.com/blog/2023/06/02/document-editor-deployment-with-docker-and-windows-server-core-2019-and-2022/llms.txt)
- [Deploying an ASP.NET Core Web Application using the Document Editor with Docker](https://www.textcontrol.com/blog/2022/09/02/deploying-an-aspnet-core-application-with-docker/llms.txt)
- [ASP.NET Core: Deploying the TX Text Control Document Editor to Linux](https://www.textcontrol.com/blog/2021/10/29/deploying-tx-text-control-to-linux/llms.txt)
- [Using TXTextControl.Web in ASP.NET Core Razor Pages](https://www.textcontrol.com/blog/2020/06/10/using-txtextcontrolweb-in-aspnet-core-razor-pages/llms.txt)
- [Building a Spell Checking Web API in ASP.NET Core](https://www.textcontrol.com/blog/2020/05/15/building-a-spell-checking-web-api-in-aspnet-core/llms.txt)
- [ReportingCloud .NET Core Wrapper Released: Creating Documents on Windows, Linux, Mac and Docker](https://www.textcontrol.com/blog/2017/08/28/reportingcloud-net-core-wrapper-released-creating-documents-on-windows-linux-mac-and-docker/llms.txt)
