microsoft / iis-docker

Dockerfile for IIS
https://hub.docker.com/r/microsoft/iis/
MIT License
288 stars 128 forks source link

Create sample or instructions on how to enable HTTP/2 #198

Closed richlander closed 5 months ago

richlander commented 2 years ago

I'm looking for a sample Dockerfile. This is intended for use with Windows Server 2022.

Context: https://docs.microsoft.com/aspnet/core/grpc/supported-platforms?view=aspnetcore-6.0#supported-aspnet-core-servers

sujitnayak commented 1 year ago

From: https://learn.microsoft.com/en-us/iis/get-started/whats-new-in-iis-10/http2-on-iis

[[ On the server, IIS running on Windows 10 or Windows Server 2016 supports HTTP/2.

IIS currently supports HTTP/2 only over TLS. When making an HTTPS connection to a web server running IIS on Windows 10, HTTP/2 is used if the client and server both support it. In IIS, we've implemented HTTP/2 as transparently as possible - you shouldn't need to change anything in your application for HTTP/2 to work. Certain HTTP/1.1 optimizations (domain sharding, inlining, etc.) are no longer recommended in HTTP/2, though, so you should plan to remove these in the future. ]]

A sample docker file that can be used for creating a https binding is attached. dockerfile.txt

The docker file is going to copy setup.ps1 from the content folder of the host's root drive and then invoke setup.ps1 powershell from there. Setup.ps1 can be any script that creates a https binding on a given IIS site. A reference script is attached.

setup.ps1.txt

The reference script gets its parametrized input (for e.g. site name) from the environment variables passed in to the docker image at runtime. The certificate PFX file for the https binding is read either from the environment variable (if the pfx file is available in host directory mounted into the container) or from a AKV secret name passed in as an environment variable.

Let me know if you have any questions.

sujitnayak commented 1 year ago

A sample docker run command line would look like:

docker run -it -p 8000:80 -p 8001:443 --name myiiscontainer -v c:\workdir:c:\workdir --env-file c:\env.txt IMAGE

Here c:\workdir on the host machine is mounted into the container and contains a PFX certificate file.

Env.txt would have the following variables:

ACCESS_KEY=XXXXXXXXXXXXXXXXXXXXXXXXXXXXX PFX_FILE=c:\workdir\server.pfx SECRET_NAME=CertPassword SITE_NAME=Default Web Site VAULT_NAME=VAULT

If the certificate PFX is password protected, SECRET_NAME is the name of the secret in AKV and ACCESS_TOKEN is the access token for AKV.