--- title: Hosting ASP.NET Core Images with Docker over HTTPS author: rick-anderson description: Learn how to host ASP.NET Core Images with Docker over HTTPS monikerRange: '>= aspnetcore-2.1' ms.author: riande ms.custom: mvc ms.date: 07/05/2019 uid: security/docker-https --- # Hosting ASP.NET Core images with Docker over HTTPS By [Rick Anderson](https://twitter.com/RickAndMSFT) ASP.NET Core uses [HTTPS by default](/aspnet/core/security/enforcing-ssl). [HTTPS](https://en.wikipedia.org/wiki/HTTPS) relies on [certificates](https://en.wikipedia.org/wiki/Public_key_certificate) for trust, identity, and encryption. This document explains how to run pre-built container images with HTTPS. See [Developing ASP.NET Core Applications with Docker over HTTPS](https://github.com/dotnet/dotnet-docker/blob/master/samples/aspnetapp/aspnetcore-docker-https-development.md) for development scenarios. This sample requires [Docker 17.06](https://docs.docker.com/release-notes/docker-ce) or later of the [Docker client](https://www.docker.com/products/docker). ## Prerequisites The [.NET Core 2.2 SDK](https://www.microsoft.com/net/download) or later is required for some of the instructions in this document. ## Certificates A certificate from a [certificate authority](https://en.wikipedia.org/wiki/Certificate_authority) is required for [production hosting](https://blogs.msdn.microsoft.com/webdev/2017/11/29/configuring-https-in-asp-net-core-across-different-platforms/) for a domain. [Let's Encrypt](https://letsencrypt.org/) is a certificate authority that offers free certificates. This document uses [self-signed development certificates](https://en.wikipedia.org/wiki/Self-signed_certificate) for hosting pre-built images over `localhost`. The instructions are similar to using production certificates. For production certs: * The `dotnet dev-certs` tool is not required. * Certificates do not need to be stored in the location used in the instructions. Any location should work, although storing certs within your site directory is not recommended. The instructions volume mount certificates into containers. You can add certificates into container images with a `COPY` command in a Dockerfile. Copying certificates into an image is not recommended: * It makes difficult to use the same image for testing with developer certificates. * It makes difficult to use the same image for Hosting with production certificates. * There is significant risk of certificate disclosure. ## Running pre-built container images with HTTPS Use the following instructions for your operating system configuration. ### Windows using Linux containers Generate certificate and configure local machine: ```dotnetcli dotnet dev-certs https -ep %USERPROFILE%\.aspnet\https\aspnetapp.pfx -p { password here } dotnet dev-certs https --trust ``` In the preceding commands, replace `{ password here }` with a password. Run the container image with ASP.NET Core configured for HTTPS: ```console docker pull mcr.microsoft.com/dotnet/core/samples:aspnetapp docker run --rm -it -p 8000:80 -p 8001:443 -e ASPNETCORE_URLS="https://+;http://+" -e ASPNETCORE_HTTPS_PORT=8001 -e ASPNETCORE_Kestrel__Certificates__Default__Password="password" -e ASPNETCORE_Kestrel__Certificates__Default__Path=/https/aspnetapp.pfx -v %USERPROFILE%\.aspnet\https:/https/ mcr.microsoft.com/dotnet/core/samples:aspnetapp ``` The password must match the password used for the certificate. ### macOS or Linux Generate certificate and configure local machine: ```dotnetcli dotnet dev-certs https -ep ${HOME}/.aspnet/https/aspnetapp.pfx -p { password here } dotnet dev-certs https --trust ``` `dotnet dev-certs https --trust` is only supported on macOS and Windows. You need to trust certs on Linux in the way that is supported by your distro. It is likely that you need to trust the certificate in your browser. In the preceding commands, replace `{ password here }` with a password. Run the container image with ASP.NET Core configured for HTTPS: ```console docker pull mcr.microsoft.com/dotnet/core/samples:aspnetapp docker run --rm -it -p 8000:80 -p 8001:443 -e ASPNETCORE_URLS="https://+;http://+" -e ASPNETCORE_HTTPS_PORT=8001 -e ASPNETCORE_Kestrel__Certificates__Default__Password="password" -e ASPNETCORE_Kestrel__Certificates__Default__Path=/https/aspnetapp.pfx -v ${HOME}/.aspnet/https:/https/ mcr.microsoft.com/dotnet/core/samples:aspnetapp ``` The password must match the password used for the certificate. ### Windows using Windows containers Generate certificate and configure local machine: ```dotnetcli dotnet dev-certs https -ep %USERPROFILE%\.aspnet\https\aspnetapp.pfx -p { password here } dotnet dev-certs https --trust ``` In the preceding commands, replace `{ password here }` with a password. Run the container image with ASP.NET Core configured for HTTPS: ```console docker pull mcr.microsoft.com/dotnet/core/samples:aspnetapp docker run --rm -it -p 8000:80 -p 8001:443 -e ASPNETCORE_URLS="https://+;http://+" -e ASPNETCORE_HTTPS_PORT=8001 -e ASPNETCORE_Kestrel__Certificates__Default__Password="password" -e ASPNETCORE_Kestrel__Certificates__Default__Path=\https\aspnetapp.pfx -v %USERPROFILE%\.aspnet\https:C:\https\ mcr.microsoft.com/dotnet/core/samples:aspnetapp ``` The password must match the password used for the certificate.