Skip to content
This repository was archived by the owner on Nov 30, 2023. It is now read-only.

Commit db9844b

Browse files
committed
Add details on getting HTTPS to work with ASP.NET Core
1 parent 10c5a87 commit db9844b

File tree

6 files changed

+271
-66
lines changed

6 files changed

+271
-66
lines changed

containers/dotnetcore-2.1/.devcontainer/devcontainer.json

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,33 @@
88
"terminal.integrated.shell.linux": "/bin/bash"
99
},
1010

11-
// Uncomment the next line if you want to publish any ports.
12-
// "appPort": [],
13-
1411
// Uncomment the next line to run commands after the container is created.
1512
// "postCreateCommand": "dotnet restore"
1613

17-
// Uncomment the next line to use a non-root user. On Linux, this will prevent
18-
// new files getting created as root, but you may need to update the USER_UID
19-
// and USER_GID in .devcontainer/Dockerfile to match your user if not 1000.
20-
// "runArgs": [ "-u", "vscode" ],
14+
// Uncomment the next line if you want to publish any ports.
15+
// "appPort": [5000, 5001],
16+
17+
"runArgs": [
18+
// Uncomment the next line to use a non-root user. On Linux, this will prevent
19+
// new files getting created as root, but you may need to update the USER_UID
20+
// and USER_GID in .devcontainer/Dockerfile to match your user if not 1000.
21+
// "-u", "vscode",
22+
23+
// [Optional] Enable HTTPS in ASP.NET by mount a local dev cert exported the dotnet CLI locally:
24+
// Windows PowerShell:
25+
// dotnet dev-certs https --trust; dotnet dev-certs https -ep "$env:USERPROFILE/.aspnet/https/aspnetapp.pfx" -p "SecurePwdGoesHere"
26+
// macOS/Linux terminal:
27+
// dotnet dev-certs https --trust && dotnet dev-certs https -ep "${HOME}/.aspnet/https/aspnetapp.pfx" -p "SecurePwdGoesHere"
28+
//
29+
// After running the command above, uncomment the lines below and open / rebuild the container.
30+
// "-v", "${env:HOME}${env:USERPROFILE}/.aspnet/https:/home/vscode/.aspnet/https"
31+
// "-e", "ASPNETCORE_Kestrel__Endpoints__Https__Url=https://*:5001",
32+
// "-e", "ASPNETCORE_Kestrel__Certificates__Default__Password=SecurePwdGoesHere",
33+
// "-e", "ASPNETCORE_Kestrel__Certificates__Default__Path=/home/vscode/.aspnet/https/aspnetapp.pfx",
34+
35+
// [Optional] Override the default HTTP endpoints - need to listen to '*' for appPort to work
36+
"-e", "ASPNETCORE_Kestrel__Endpoints__Http__Url=http://*:5000"
37+
],
2138

2239
// Add the IDs of extensions you want installed when the container is created in the array below.
2340
"extensions": [

containers/dotnetcore-2.1/README.md

Lines changed: 66 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,28 +12,79 @@
1212

1313
## Using this definition with an existing folder
1414

15-
A few notes on this definition:
15+
While the definition itself works unmodified, there are some tips that can help you deal with some of the defaults .NET Core uses.
1616

17-
1. Only the integrated terminal is supported by the Remote - Containers extension. You may need to modify `launch.json` configurations to include the following value if an external console is used.
17+
### Using appPort with ASP.NET Core
1818

19-
```json
20-
"console": "integratedTerminal"
21-
```
19+
By default, ASP.NET Core only listens to localhost. The challenge is that ASP.NET Core thinks that localhost is inside the container. If you use the `appPort` property in `.devcontainer/devcontainer.json`, the port is [published](https://docs.docker.com/config/containers/container-networking/#published-ports) rather than forwarded. So you can override the defaults so that ASP.NET will listen to traffic from your local machine as well.
2220

23-
2. Given how frequently ASP.NET applications use Node.js for front end code, this container also includes Node.js. You can change the version of Node.js installed or disable its installation by updating these lines in `.devcontainer/Dockerfile`.
21+
```json
22+
"appPort": [5000, 5001],
23+
"runArgs": [
24+
"-e", "ASPNETCORE_Kestrel__Endpoints__Http__Url=http://*:5000",
25+
"-e", "ASPNETCORE_Kestrel__Endpoints__Https__Url=https://*:5001"
26+
]
27+
```
2428

25-
```Dockerfile
26-
ARG INSTALL_NODE="true"
27-
ARG NODE_MAJOR_VERSION="10"
28-
```
29+
Rebuild the container using the **Remote-Containers: Rebuild Container** command from the Command Palette (<kbd>F1</kbd>) if you've already opened your folder in a container so the settings take effect.
2930

30-
3. If you would like to install the Azure CLI update this line in `.devcontainer/Dockerfile`:
31+
### Enabling HTTPS in ASP.NET Core
3132

32-
```Dockerfile
33-
ARG INSTALL_AZURE_CLI="true"
34-
```
33+
To enable HTTPS in ASP.NET, you can mount an exported copy of your local dev certificate. First, export it using the following command:
3534

36-
Beyond that, just follow these steps to use the definition:
35+
**Windows PowerShell**
36+
37+
```powershell
38+
dotnet dev-certs https --trust; dotnet dev-certs https -ep "$env:USERPROFILE/.aspnet/https/aspnetapp.pfx" -p "SecurePwdGoesHere"
39+
```
40+
41+
**macOS/Linux terminal**
42+
43+
```powershell
44+
dotnet dev-certs https --trust && dotnet dev-certs https -ep "${HOME}/.aspnet/https/aspnetapp.pfx" -p "SecurePwdGoesHere"
45+
```
46+
47+
Next, add the following in the `runArgs` array in `.devcontainer/devcontainer.json` (assuming port 5000 and 5001 are the correct ports):
48+
49+
```json
50+
"appPort": [5000, 5001],
51+
"runArgs": [
52+
"-e", "ASPNETCORE_Kestrel__Endpoints__Http__Url=http://*:5000",
53+
"-e", "ASPNETCORE_Kestrel__Endpoints__Https__Url=https://*:5001",
54+
"-v", "${env:HOME}${env:USERPROFILE}/.aspnet/https:/home/vscode/.aspnet/https",
55+
"-e", "ASPNETCORE_Kestrel__Certificates__Default__Password=SecurePwdGoesHere",
56+
"-e", "ASPNETCORE_Kestrel__Certificates__Default__Path=/home/vscode/.aspnet/https/aspnetapp.pfx"
57+
]
58+
```
59+
60+
Rebuild the container using the **Remote-Containers: Rebuild Container** command from the Command Palette (<kbd>F1</kbd>) if you've already opened your folder in a container so the settings take effect.
61+
62+
### Debug Configuration
63+
64+
Only the integrated terminal is supported by the Remote - Containers extension. You may need to modify `launch.json` configurations to include the following value if an external console is used.
65+
66+
```json
67+
"console": "integratedTerminal"
68+
```
69+
70+
### Installing Node.js or the Azure CLI
71+
72+
Given how frequently ASP.NET applications use Node.js for front end code, this container also includes Node.js. You can change the version of Node.js installed or disable its installation by updating these lines in `.devcontainer/Dockerfile`.
73+
74+
```Dockerfile
75+
ARG INSTALL_NODE="true"
76+
ARG NODE_MAJOR_VERSION="10"
77+
```
78+
79+
If you would like to install the Azure CLI update this line in `.devcontainer/Dockerfile`:
80+
81+
```Dockerfile
82+
ARG INSTALL_AZURE_CLI="true"
83+
```
84+
85+
Rebuild the container using the **Remote-Containers: Rebuild Container** command from the Command Palette (<kbd>F1</kbd>) if you've already opened your folder in a container so the settings take effect.
86+
87+
### Adding the definition to your folder
3788

3889
1. If this is your first time using a development container, please follow the [getting started steps](https://aka.ms/vscode-remote/containers/getting-started) to set up your machine.
3990

containers/dotnetcore-2.2/.devcontainer/devcontainer.json

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,33 @@
88
"terminal.integrated.shell.linux": "/bin/bash"
99
},
1010

11-
// Uncomment the next line if you want to publish any ports.
12-
// "appPort": [],
13-
1411
// Uncomment the next line to run commands after the container is created.
1512
// "postCreateCommand": "dotnet restore"
1613

17-
// Uncomment the next line to use a non-root user. On Linux, this will prevent
18-
// new files getting created as root, but you may need to update the USER_UID
19-
// and USER_GID in .devcontainer/Dockerfile to match your user if not 1000.
20-
// "runArgs": [ "-u", "vscode" ],
14+
// Uncomment the next line if you want to publish any ports.
15+
// "appPort": [5000, 5001],
16+
17+
"runArgs": [
18+
// Uncomment the next line to use a non-root user. On Linux, this will prevent
19+
// new files getting created as root, but you may need to update the USER_UID
20+
// and USER_GID in .devcontainer/Dockerfile to match your user if not 1000.
21+
// "-u", "vscode",
22+
23+
// [Optional] Enable HTTPS in ASP.NET by mount a local dev cert exported the dotnet CLI locally:
24+
// Windows PowerShell:
25+
// dotnet dev-certs https --trust; dotnet dev-certs https -ep "$env:USERPROFILE/.aspnet/https/aspnetapp.pfx" -p "SecurePwdGoesHere"
26+
// macOS/Linux terminal:
27+
// dotnet dev-certs https --trust && dotnet dev-certs https -ep "${HOME}/.aspnet/https/aspnetapp.pfx" -p "SecurePwdGoesHere"
28+
//
29+
// After running the command above, uncomment the lines below and open / rebuild the container.
30+
// "-v", "${env:HOME}${env:USERPROFILE}/.aspnet/https:/home/vscode/.aspnet/https"
31+
// "-e", "ASPNETCORE_Kestrel__Endpoints__Https__Url=https://*:5001",
32+
// "-e", "ASPNETCORE_Kestrel__Certificates__Default__Password=SecurePwdGoesHere",
33+
// "-e", "ASPNETCORE_Kestrel__Certificates__Default__Path=/home/vscode/.aspnet/https/aspnetapp.pfx",
34+
35+
// [Optional] Override the default HTTP endpoints - need to listen to '*' for appPort to work
36+
"-e", "ASPNETCORE_Kestrel__Endpoints__Http__Url=http://*:5000"
37+
],
2138

2239
// Add the IDs of extensions you want installed when the container is created in the array below.
2340
"extensions": [

containers/dotnetcore-2.2/README.md

Lines changed: 66 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,28 +12,79 @@
1212

1313
## Using this definition with an existing folder
1414

15-
A few notes on this definition:
15+
While the definition itself works unmodified, there are some tips that can help you deal with some of the defaults .NET Core uses.
1616

17-
1. Only the integrated terminal is supported by the Remote - Containers extension. You may need to modify `launch.json` configurations to include the following value if an external console is used.
17+
### Using appPort with ASP.NET Core
1818

19-
```json
20-
"console": "integratedTerminal"
21-
```
19+
By default, ASP.NET Core only listens to localhost. The challenge is that ASP.NET Core thinks that localhost is inside the container. If you use the `appPort` property in `.devcontainer/devcontainer.json`, the port is [published](https://docs.docker.com/config/containers/container-networking/#published-ports) rather than forwarded. So you can override the defaults so that ASP.NET will listen to traffic from your local machine as well.
2220

23-
2. Given how frequently ASP.NET applications use Node.js for front end code, this container also includes Node.js. You can change the version of Node.js installed or disable its installation by updating these lines in `.devcontainer/Dockerfile`.
21+
```json
22+
"appPort": [5000, 5001],
23+
"runArgs": [
24+
"-e", "ASPNETCORE_Kestrel__Endpoints__Http__Url=http://*:5000",
25+
"-e", "ASPNETCORE_Kestrel__Endpoints__Https__Url=https://*:5001"
26+
]
27+
```
2428

25-
```Dockerfile
26-
ARG INSTALL_NODE="true"
27-
ARG NODE_MAJOR_VERSION="10"
28-
```
29+
Rebuild the container using the **Remote-Containers: Rebuild Container** command from the Command Palette (<kbd>F1</kbd>) if you've already opened your folder in a container so the settings take effect.
2930

30-
3. If you would like to install the Azure CLI update this line in `.devcontainer/Dockerfile`:
31+
### Enabling HTTPS in ASP.NET Core
3132

32-
```Dockerfile
33-
ARG INSTALL_AZURE_CLI="true"
34-
```
33+
To enable HTTPS in ASP.NET, you can mount an exported copy of your local dev certificate. First, export it using the following command:
3534

36-
Beyond that, just follow these steps to use the definition:
35+
**Windows PowerShell**
36+
37+
```powershell
38+
dotnet dev-certs https --trust; dotnet dev-certs https -ep "$env:USERPROFILE/.aspnet/https/aspnetapp.pfx" -p "SecurePwdGoesHere"
39+
```
40+
41+
**macOS/Linux terminal**
42+
43+
```powershell
44+
dotnet dev-certs https --trust && dotnet dev-certs https -ep "${HOME}/.aspnet/https/aspnetapp.pfx" -p "SecurePwdGoesHere"
45+
```
46+
47+
Next, add the following in the `runArgs` array in `.devcontainer/devcontainer.json` (assuming port 5000 and 5001 are the correct ports):
48+
49+
```json
50+
"appPort": [5000, 5001],
51+
"runArgs": [
52+
"-e", "ASPNETCORE_Kestrel__Endpoints__Http__Url=http://*:5000",
53+
"-e", "ASPNETCORE_Kestrel__Endpoints__Https__Url=https://*:5001",
54+
"-v", "${env:HOME}${env:USERPROFILE}/.aspnet/https:/home/vscode/.aspnet/https",
55+
"-e", "ASPNETCORE_Kestrel__Certificates__Default__Password=SecurePwdGoesHere",
56+
"-e", "ASPNETCORE_Kestrel__Certificates__Default__Path=/home/vscode/.aspnet/https/aspnetapp.pfx"
57+
]
58+
```
59+
60+
Rebuild the container using the **Remote-Containers: Rebuild Container** command from the Command Palette (<kbd>F1</kbd>) if you've already opened your folder in a container so the settings take effect.
61+
62+
### Debug Configuration
63+
64+
Only the integrated terminal is supported by the Remote - Containers extension. You may need to modify `launch.json` configurations to include the following value if an external console is used.
65+
66+
```json
67+
"console": "integratedTerminal"
68+
```
69+
70+
### Installing Node.js or the Azure CLI
71+
72+
Given how frequently ASP.NET applications use Node.js for front end code, this container also includes Node.js. You can change the version of Node.js installed or disable its installation by updating these lines in `.devcontainer/Dockerfile`.
73+
74+
```Dockerfile
75+
ARG INSTALL_NODE="true"
76+
ARG NODE_MAJOR_VERSION="10"
77+
```
78+
79+
If you would like to install the Azure CLI update this line in `.devcontainer/Dockerfile`:
80+
81+
```Dockerfile
82+
ARG INSTALL_AZURE_CLI="true"
83+
```
84+
85+
Rebuild the container using the **Remote-Containers: Rebuild Container** command from the Command Palette (<kbd>F1</kbd>) if you've already opened your folder in a container so the settings take effect.
86+
87+
### Adding the definition to your folder
3788

3889
1. If this is your first time using a development container, please follow the [getting started steps](https://aka.ms/vscode-remote/containers/getting-started) to set up your machine.
3990

containers/dotnetcore-3.0/.devcontainer/devcontainer.json

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,34 @@
88
"terminal.integrated.shell.linux": "/bin/bash"
99
},
1010

11-
// Uncomment the next line if you want to publish any ports.
12-
// "appPort": [],
13-
1411
// Uncomment the next line to run commands after the container is created.
1512
// "postCreateCommand": "dotnet restore",
1613

17-
// Uncomment the next line to use a non-root user. On Linux, this will prevent
18-
// new files getting created as root, but you may need to update the USER_UID
19-
// and USER_GID in .devcontainer/Dockerfile to match your user if not 1000.
20-
// "runArgs": [ "-u", "vscode" ],
14+
// Uncomment the next line if you want to publish any ports.
15+
// "appPort": [5000, 5001],
16+
17+
"runArgs": [
18+
// Uncomment the next line to use a non-root user. On Linux, this will prevent
19+
// new files getting created as root, but you may need to update the USER_UID
20+
// and USER_GID in .devcontainer/Dockerfile to match your user if not 1000.
21+
// "-u", "vscode",
22+
23+
// [Optional] Enable HTTPS in ASP.NET by mount a local dev cert exported the dotnet CLI locally:
24+
// Windows PowerShell:
25+
// dotnet dev-certs https --trust; dotnet dev-certs https -ep "$env:USERPROFILE/.aspnet/https/aspnetapp.pfx" -p "SecurePwdGoesHere"
26+
// macOS/Linux terminal:
27+
// dotnet dev-certs https --trust && dotnet dev-certs https -ep "${HOME}/.aspnet/https/aspnetapp.pfx" -p "SecurePwdGoesHere"
28+
//
29+
// After running the command above, uncomment the lines below and open / rebuild the container.
30+
// "-v", "${env:HOME}${env:USERPROFILE}/.aspnet/https:/home/vscode/.aspnet/https"
31+
// "-e", "ASPNETCORE_Kestrel__Endpoints__Https__Url=https://*:5001",
32+
// "-e", "ASPNETCORE_Kestrel__Certificates__Default__Password=SecurePwdGoesHere",
33+
// "-e", "ASPNETCORE_Kestrel__Certificates__Default__Path=/home/vscode/.aspnet/https/aspnetapp.pfx",
34+
35+
// [Optional] Override the default HTTP endpoints - need to listen to '*' for appPort to work
36+
"-e", "ASPNETCORE_Kestrel__Endpoints__Http__Url=http://*:5000"
37+
],
38+
2139

2240
// Add the IDs of extensions you want installed when the container is created in the array below.
2341
"extensions": [

0 commit comments

Comments
 (0)