Skip to content

Commit d4affeb

Browse files
mon prep (#33427)
* mon prep * mon prep * mon prep
1 parent 41d87ef commit d4affeb

File tree

2 files changed

+168
-3
lines changed

2 files changed

+168
-3
lines changed

aspnetcore/security/docker-compose-https.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,16 @@
22
title: Hosting ASP.NET Core image in container using docker compose with HTTPS
33
author: ravipal
44
description: Learn how to host ASP.NET Core Images with Docker Compose over HTTPS
5-
monikerRange: '>= aspnetcore-2.1'
65
ms.author: wpickett
76
ms.custom: mvc
87
ms.date: 03/28/2020
98
uid: security/docker-compose-https
109
---
1110
# Hosting ASP.NET Core images with Docker Compose over HTTPS
1211

13-
<!-- This topic drops loc for "Let's Encrypt" -->
12+
:::moniker range=">= aspnetcore-8.0"
1413

15-
ASP.NET Core uses [HTTPS by default](./enforcing-ssl.md). [HTTPS](https://en.wikipedia.org/wiki/HTTPS) relies on [certificates](https://en.wikipedia.org/wiki/Public_key_certificate) for trust, identity, and encryption.
14+
ASP.NET Core uses [HTTPS by default](~/security/enforcing-ssl.md). [HTTPS](https://en.wikipedia.org/wiki/HTTPS) relies on [certificates](https://en.wikipedia.org/wiki/Public_key_certificate) for trust, identity, and encryption.
1615

1716
This document explains how to run pre-built container images with HTTPS.
1817

@@ -171,3 +170,7 @@ docker-compose -f "docker-compose.debug.yml" up -d
171170
## See also
172171

173172
* [`dotnet dev-certs`](/dotnet/core/tools/dotnet-dev-certs)
173+
174+
:::moniker-end
175+
176+
[!INCLUDE[](~/security/includes/docker-compose-https7.md)]
Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
:::moniker range=">= aspnetcore-2.1 < aspnetcore-8.0"
2+
3+
ASP.NET Core uses [HTTPS by default](~/security/enforcing-ssl.md). [HTTPS](https://en.wikipedia.org/wiki/HTTPS) relies on [certificates](https://en.wikipedia.org/wiki/Public_key_certificate) for trust, identity, and encryption.
4+
5+
This document explains how to run pre-built container images with HTTPS.
6+
7+
See [Developing ASP.NET Core Applications with Docker over HTTPS](https://github.com/dotnet/dotnet-docker/blob/main/samples/run-aspnetcore-https-development.md) for development scenarios.
8+
9+
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).
10+
11+
## Prerequisites
12+
13+
The [.NET Core 2.2 SDK](https://dotnet.microsoft.com/download) or later is required for some of the instructions in this document.
14+
15+
## Certificates
16+
17+
A certificate from a [certificate authority](https://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. [:::no-loc text="Let's Encrypt":::](https://letsencrypt.org/) is a certificate authority that offers free certificates.
18+
19+
This document uses [self-signed development certificates](https://wikipedia.org/wiki/Self-signed_certificate) for hosting pre-built images over `localhost`. The instructions are similar to using production certificates.
20+
21+
For production certificates:
22+
23+
* The `dotnet dev-certs` tool is not required.
24+
* Certificates don't need to be stored in the location used in the instructions. Store the certificates in any location outside the site directory.
25+
26+
The instructions contained in the following section volume mount certificates into containers using the `volumes` property in *docker-compose.yml.* You could add certificates into container images with a `COPY` command in a *Dockerfile*, but it's not recommended. Copying certificates into an image isn't recommended for the following reasons:
27+
28+
* It makes it difficult to use the same image for testing with developer certificates.
29+
* It makes it difficult to use the same image for Hosting with production certificates.
30+
* There is significant risk of certificate disclosure.
31+
32+
## Starting a container with https support using docker compose
33+
34+
Use the following instructions for your operating system configuration.
35+
36+
### Windows using Linux containers
37+
38+
Generate certificate and configure local machine:
39+
40+
```powershell
41+
dotnet dev-certs https -ep "$env:USERPROFILE\.aspnet\https\aspnetapp.pfx" -p $CREDENTIAL_PLACEHOLDER$
42+
dotnet dev-certs https --trust
43+
```
44+
45+
The previous command using the .NET CLI:
46+
47+
```dotnetcli
48+
dotnet dev-certs https -ep %USERPROFILE%\.aspnet\https\aspnetapp.pfx -p $CREDENTIAL_PLACEHOLDER$
49+
dotnet dev-certs https --trust
50+
```
51+
52+
In the preceding commands, replace `$CREDENTIAL_PLACEHOLDER$` with a password.
53+
54+
Create a _docker-compose.debug.yml_ file with the following content:
55+
56+
```yaml
57+
version: '3.4'
58+
59+
services:
60+
webapp:
61+
image: mcr.microsoft.com/dotnet/samples:aspnetapp
62+
ports:
63+
- 80
64+
- 443
65+
environment:
66+
- ASPNETCORE_ENVIRONMENT=Development
67+
- ASPNETCORE_URLS=https://+:443;http://+:80
68+
- ASPNETCORE_Kestrel__Certificates__Default__Password=password
69+
- ASPNETCORE_Kestrel__Certificates__Default__Path=/https/aspnetapp.pfx
70+
volumes:
71+
- ~/.aspnet/https:/https:ro
72+
```
73+
The password specified in the docker compose file must match the password used for the certificate.
74+
75+
Start the container with ASP.NET Core configured for HTTPS:
76+
77+
```console
78+
docker-compose -f "docker-compose.debug.yml" up -d
79+
```
80+
81+
### macOS or Linux
82+
83+
Generate certificate and configure local machine:
84+
85+
```dotnetcli
86+
dotnet dev-certs https -ep ${HOME}/.aspnet/https/aspnetapp.pfx -p $CREDENTIAL_PLACEHOLDER$
87+
dotnet dev-certs https --trust
88+
```
89+
90+
`dotnet dev-certs https --trust` is only supported on macOS and Windows. You need to trust certificates on Linux in the way that is supported by your distribution. It is likely that you need to trust the certificate in your browser.
91+
92+
In the preceding commands, replace `$CREDENTIAL_PLACEHOLDER$` with a password.
93+
94+
Create a _docker-compose.debug.yml_ file with the following content:
95+
96+
```yaml
97+
version: '3.4'
98+
99+
services:
100+
webapp:
101+
image: mcr.microsoft.com/dotnet/samples:aspnetapp
102+
ports:
103+
- 80
104+
- 443
105+
environment:
106+
- ASPNETCORE_ENVIRONMENT=Development
107+
- ASPNETCORE_URLS=https://+:443;http://+:80
108+
- ASPNETCORE_Kestrel__Certificates__Default__Password=password
109+
- ASPNETCORE_Kestrel__Certificates__Default__Path=/https/aspnetapp.pfx
110+
volumes:
111+
- ~/.aspnet/https:/https:ro
112+
```
113+
The password specified in the docker compose file must match the password used for the certificate.
114+
115+
Start the container with ASP.NET Core configured for HTTPS:
116+
117+
```console
118+
docker-compose -f "docker-compose.debug.yml" up -d
119+
```
120+
121+
### Windows using Windows containers
122+
123+
Generate certificate and configure local machine:
124+
125+
```dotnetcli
126+
dotnet dev-certs https -ep %USERPROFILE%\.aspnet\https\aspnetapp.pfx -p $CREDENTIAL_PLACEHOLDER$
127+
dotnet dev-certs https --trust
128+
```
129+
130+
In the preceding commands, replace `$CREDENTIAL_PLACEHOLDER$` with a password.
131+
132+
Create a _docker-compose.debug.yml_ file with the following content:
133+
134+
```yaml
135+
version: '3.4'
136+
137+
services:
138+
webapp:
139+
image: mcr.microsoft.com/dotnet/samples:aspnetapp
140+
ports:
141+
- 80
142+
- 443
143+
environment:
144+
- ASPNETCORE_ENVIRONMENT=Development
145+
- ASPNETCORE_URLS=https://+:443;http://+:80
146+
- ASPNETCORE_Kestrel__Certificates__Default__Password=password
147+
- ASPNETCORE_Kestrel__Certificates__Default__Path=C:\https\aspnetapp.pfx
148+
volumes:
149+
- ${USERPROFILE}\.aspnet\https:C:\https:ro
150+
```
151+
The password specified in the docker compose file must match the password used for the certificate.
152+
153+
Start the container with ASP.NET Core configured for HTTPS:
154+
155+
```console
156+
docker-compose -f "docker-compose.debug.yml" up -d
157+
```
158+
159+
## See also
160+
161+
* [`dotnet dev-certs`](/dotnet/core/tools/dotnet-dev-certs)
162+
:::moniker-end

0 commit comments

Comments
 (0)