i have a web api and want create docker image, so i created docker file and trying to run but it is throwing exception when creating IIS web site
here is docker file
# escape=`
FROM mcr.microsoft.com/windows/servercore:ltsc2019
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]
# configure the new site in IIS.
RUN `
New-Item -Path "C:\" -Name "Apigateway" -ItemType "directory";`
Import-module Webadministration;`
New-IISSite -Name "AxApigateway" -BindingInformation "*:8080:" -PhysicalPath 'C:\Apigateway';`
# This instruction tells the container to listen on port 83.
EXPOSE 83
# The final instruction copies the site you published earlier into the container.
COPY /Published/ C:\Apigateway
Jayraj ChhayaPosted Dec 22, 2023, 5:51 AM
To deploy a C# Web API on an IIS server using Docker, you can use the following Dockerfile:
In this Dockerfile, we start with the
mcr.microsoft.com/windows/servercore:ltsc2019base image, which provides the Windows Server Core operating system. We then install IIS using theInstall-WindowsFeaturecommand.Next, we create a directory named "Apigateway" in the container's C drive using the
New-Itemcommand. We copy the published API files from the/Published/directory on the host machine to theC:\Apigatewaydirectory in the container using theCOPYcommand.Finally, we configure the new site in IIS using the
New-IISSitecommand, specifying the site name, binding information, and physical path. We expose port 8080 using theEXPOSEinstruction. TheCMDinstruction starts the IIS service using theServiceMonitor.exeutility.Make sure to replace
/Published/with the actual path to your published API files on the host machine.With this Dockerfile, you can build the Docker image using the
docker buildcommand and run it using thedocker runcommand. The API will be accessible on port 8080 of the container.Mayooran NavamanyPosted Dec 22, 2023, 5:23 AM
Use of Forward Slash in COPY command: The path separator in Docker is always forward slash ("/"), regardless of the host operating system. Therefore, in the COPY command, you should use forward slashes instead of backslashes.
Change:
to:
Incorrect Site Name in New-IISSite: In the
New-IISSitecommand, the site name you specified is "AxApigateway," but when creating the directory and copying files, you used "Apigateway." Make sure they match.Change:
to:
With these changes, your Dockerfile should look like this:
Make these changes and try building and running the Docker image again.