Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/dotnet/dotnet-docker into…
Browse files Browse the repository at this point in the history
… merge-master
  • Loading branch information
MichaelSimons committed May 21, 2018
2 parents 6fef2fb + 5231c5d commit faa0b48
Show file tree
Hide file tree
Showing 57 changed files with 3,863 additions and 2,552 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ Type the following command to run a sample web application:
docker run -it --rm -p 8000:80 --name aspnetcore_sample microsoft/dotnet-samples:aspnetapp
```

After the application starts, navigate to `http://localhost:8000` in your web browser. You need to navigate to the application via IP address instead of `localhost` for Windows containers, which is demonstrated in [View the ASP.NET Core app in a running container on Windows](https://github.com/dotnet/dotnet-docker/blob/master/samples/aspnetapp/README.md#view-the-aspnet-core-app-in-a-running-container-on-windows).
After the application starts, navigate to `http://localhost:8000` in your web browser. On Windows, you may need to navigate to the container via IP address. See [ASP.NET Core apps in Windows Containers](https://github.com/dotnet/dotnet-docker/blob/master/samples/aspnetapp/aspnetcore-docker-windows.md) for instructions on determining the IP address, using the value of `--name` that you used in `docker run`.

See [Hosting ASP.NET Core Images with Docker over HTTPS](https://github.com/dotnet/dotnet-docker/blob/master/samples/aspnetapp/aspnetcore-docker-https.md) to use HTTPS with this image.

## Complete set of Tags

Expand Down Expand Up @@ -175,6 +177,7 @@ If you have any problems with or questions about this image, please contact us t

* [.NET Core license](https://github.com/dotnet/dotnet-docker/blob/master/LICENSE)
* [Windows Nano Server license](https://hub.docker.com/r/microsoft/nanoserver/) (only applies to Windows containers)
* [Pricing and licensing for Windows Server 2016](https://www.microsoft.com/en-us/cloud-platform/windows-server-pricing)

## Related Repos

Expand Down
3 changes: 1 addition & 2 deletions build-pipeline/pipeline-samples.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@
{
"Name": "dotnet-docker-linux-arm32v7-images",
"Parameters": {
"imageBuilder.manifest": "manifest.samples.json",
"docker.dockerConfigArgs": "-v /var/run/docker.sock:/var/run/docker.sock"
"imageBuilder.manifest": "manifest.samples.json"
}
}
]
Expand Down
26 changes: 14 additions & 12 deletions manifest.samples.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,30 +11,30 @@
},
"platforms": [
{
"dockerfile": "samples/dotnetapp/Dockerfile.preview",
"dockerfile": "samples/dotnetapp/Dockerfile",
"os": "linux",
"tags": {
"dotnetapp-stretch": {}
}
},
{
"dockerfile": "samples/dotnetapp/Dockerfile.preview",
"dockerfile": "samples/dotnetapp/Dockerfile",
"os": "windows",
"osVersion": "sac2016",
"tags": {
"dotnetapp-nanoserver-sac2016": {}
}
},
{
"dockerfile": "samples/dotnetapp/Dockerfile.preview",
"dockerfile": "samples/dotnetapp/Dockerfile",
"os": "windows",
"osVersion": "1709",
"tags": {
"dotnetapp-nanoserver-1709": {}
}
},
{
"dockerfile": "samples/dotnetapp/Dockerfile.preview",
"dockerfile": "samples/dotnetapp/Dockerfile",
"os": "windows",
"osVersion": "1803",
"tags": {
Expand All @@ -43,11 +43,12 @@
},
{
"architecture": "arm",
"dockerfile": "samples/dotnetapp/Dockerfile.preview",
"dockerfile": "samples/dotnetapp/Dockerfile",
"os": "linux",
"tags": {
"dotnetapp-stretch-arm32v7": {}
}
},
"variant": "v7"
}
]
},
Expand All @@ -57,30 +58,30 @@
},
"platforms": [
{
"dockerfile": "samples/aspnetapp/Dockerfile.preview",
"dockerfile": "samples/aspnetapp/Dockerfile",
"os": "linux",
"tags": {
"aspnetapp-stretch": {}
}
},
{
"dockerfile": "samples/aspnetapp/Dockerfile.preview",
"dockerfile": "samples/aspnetapp/Dockerfile",
"os": "windows",
"osVersion": "sac2016",
"tags": {
"aspnetapp-nanoserver-sac2016": {}
}
},
{
"dockerfile": "samples/aspnetapp/Dockerfile.preview",
"dockerfile": "samples/aspnetapp/Dockerfile",
"os": "windows",
"osVersion": "1709",
"tags": {
"aspnetapp-nanoserver-1709": {}
}
},
{
"dockerfile": "samples/aspnetapp/Dockerfile.preview",
"dockerfile": "samples/aspnetapp/Dockerfile",
"os": "windows",
"osVersion": "1803",
"tags": {
Expand All @@ -89,11 +90,12 @@
},
{
"architecture": "arm",
"dockerfile": "samples/aspnetapp/Dockerfile.preview",
"dockerfile": "samples/aspnetapp/Dockerfile",
"os": "linux",
"tags": {
"aspnetapp-stretch-arm32v7": {}
}
},
"variant": "v7"
}
]
}
Expand Down
4 changes: 3 additions & 1 deletion samples/README.DockerHub.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ Type the following command to run a sample web application:
docker run -it --rm -p 8000:80 --name aspnetcore_sample microsoft/dotnet-samples:aspnetapp
```

After the application starts, navigate to `http://localhost:8000` in your web browser. You need to navigate to the application via IP address instead of `localhost` for Windows containers, which is demonstrated in [View the ASP.NET Core app in a running container on Windows](https://github.com/dotnet/dotnet-docker/blob/master/samples/aspnetapp/README.md#view-the-aspnet-core-app-in-a-running-container-on-windows).
After the application starts, navigate to `http://localhost:8000` in your web browser. On Windows, you may need to navigate to the container via IP address. See [ASP.NET Core apps in Windows Containers](https://github.com/dotnet/dotnet-docker/blob/master/samples/aspnetapp/aspnetcore-docker-windows.md) for instructions on determining the IP address, using the value of `--name` that you used in `docker run`.

See [Hosting ASP.NET Core Images with Docker over HTTPS](https://github.com/dotnet/dotnet-docker/blob/master/samples/aspnetapp/aspnetcore-docker-https.md) to use HTTPS with this image.

# Linux amd64 tags

Expand Down
19 changes: 19 additions & 0 deletions samples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,20 @@ Type the following [Docker](https://www.docker.com/products/docker) command:
docker run --rm microsoft/dotnet-samples
```

## Try a pre-built ASP.NET Core Docker Image

You can quickly run a container with a pre-built [sample ASP.NET Core Docker image](https://hub.docker.com/r/microsoft/dotnet-samples/), based on this [sample](Dockerfile).

Type the following command to run a sample with [Docker](https://www.docker.com/products/docker):

```console
docker run --name aspnetcore_sample --rm -it -p 8000:80 microsoft/dotnet-samples:aspnetapp
```

After the application starts, navigate to `http://localhost:8000` in your web browser. On Windows, you may need to navigate to the container via IP address. See [ASP.NET Core apps in Windows Containers](aspnetapp/aspnetcore-docker-windows.md) for instructions on determining the IP address, using the value of `--name` that you used in `docker run`.

See [Hosting ASP.NET Core Images with Docker over HTTPS](aspnetapp/aspnetcore-docker-https.md) to use HTTPS with this image.

## Building .NET Core Apps with Docker

* [.NET Core Docker Sample](dotnetapp/README.md) - This [sample](dotnetapp/Dockerfile) builds, tests, and runs the sample. It includes and builds multiple projects.
Expand All @@ -24,6 +38,11 @@ docker run --rm microsoft/dotnet-samples
* [Develop .NET Core Applications](dotnetapp/dotnet-docker-dev-in-container.md) - This sample shows how to develop, build and test .NET Core applications with Docker without the need to install the .NET Core SDK.
* [Develop ASP.NET Core Applications](aspnetapp/aspnet-docker-dev-in-container.md) - This sample shows how to develop and test ASP.NET Core applications with Docker without the need to install the .NET Core SDK.

## Host ASP.NET Core Apps over HTTPS with Docker

* [Hosting ASP.NET Core Images with Docker over HTTPS](aspnetapp/aspnetcore-docker-https.md)
* [Developing ASP.NET Core Applications with Docker over HTTPS](aspnetapp/aspnetcore-docker-https-development.md)

## Push Images to a Container Registry

* [Push Docker Images to Azure Container Registry](dotnetapp/push-image-to-acr.md)
Expand Down
4 changes: 2 additions & 2 deletions samples/aspnetapp/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM microsoft/dotnet:2.0-sdk AS build
FROM microsoft/dotnet:2.1-sdk AS build
WORKDIR /app

# copy csproj and restore as distinct layers
Expand All @@ -12,7 +12,7 @@ WORKDIR /app/aspnetapp
RUN dotnet publish -c release -o out


FROM microsoft/aspnetcore:2.0 AS runtime
FROM microsoft/dotnet:2.1-aspnetcore-runtime AS runtime
WORKDIR /app
COPY --from=build /app/aspnetapp/out ./
ENTRYPOINT ["dotnet", "aspnetapp.dll"]
4 changes: 2 additions & 2 deletions samples/aspnetapp/Dockerfile.nanoserver-sac2016
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM microsoft/dotnet:2.0-sdk AS build
FROM microsoft/dotnet:2.1-sdk AS build
WORKDIR /app

# copy csproj and restore as distinct layers
Expand All @@ -12,7 +12,7 @@ WORKDIR /app/aspnetapp
RUN dotnet publish -c release -o out


FROM microsoft/aspnetcore:2.0-nanoserver-sac2016 AS runtime
FROM microsoft/dotnet:2.1-aspnetcore-runtime-nanoserver-sac2016 AS runtime
WORKDIR /app
COPY --from=build /app/aspnetapp/out ./
ENTRYPOINT ["dotnet", "aspnetapp.dll"]
1 change: 1 addition & 0 deletions samples/aspnetapp/Dockerfile.preview
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# This Dockerfile uses nightly preview builds for .NET Core 2.1 RTM
FROM microsoft/dotnet-nightly:2.1-sdk AS build
WORKDIR /app

Expand Down
70 changes: 22 additions & 48 deletions samples/aspnetapp/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# ASP.NET Core Docker Sample

This [sample](Dockerfile) demonstrates how to use ASP.NET Core and Docker together. The sample works with both Linux and Windows containers and can also be used without Docker. There are also instructions that demonstrate how to push the sample to [Azure Container Registry](../dotnetapp/push-image-to-acr.md) and test it with [Azure Container Instance](deploy-container-to-aci.md).
This [sample Dockerfile](Dockerfile) demonstrates how to use ASP.NET Core and Docker together. The sample works with both Linux and Windows containers and can also be used without Docker. There are also instructions that demonstrate how to push the sample to [Azure Container Registry](../dotnetapp/push-image-to-acr.md) and test it with [Azure Container Instance](deploy-container-to-aci.md). You can [configure ASP.NET Core to use HTTPS with Docker](aspnetcore-docker-https.md).

The sample builds the application in a container based on the larger [.NET Core SDK Docker image](https://hub.docker.com/r/microsoft/dotnet/). It builds and tests the application and then copies the final build result into a Docker image based on the smaller [ASP.NET Core Docker Runtime image](https://hub.docker.com/r/microsoft/aspnetcore/). It uses Docker [multi-stage build](https://github.com/dotnet/announcements/issues/18) and [multi-arch tags](https://github.com/dotnet/announcements/issues/14).
The sample builds the application in a container based on the larger [.NET Core SDK Docker image](https://hub.docker.com/r/microsoft/dotnet/). It builds the application and then copies the final build result into a Docker image based on the smaller [ASP.NET Core Docker Runtime image](https://hub.docker.com/r/microsoft/aspnetcore/).

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).

Expand All @@ -16,7 +16,9 @@ Type the following command to run a sample with [Docker](https://www.docker.com/
docker run --name aspnetcore_sample --rm -it -p 8000:80 microsoft/dotnet-samples:aspnetapp
```

After the application starts, navigate to `http://localhost:8000` in your web browser. On earlier versions of Windows 10 and Windows Server, you need to navigate to the application via IP address instead of `localhost` for Windows containers, which is demonstrated in the [View the ASP.NET Core app in a running container on Windows](#view-the-aspnet-core-app-in-a-running-container-on-windows) section.
After the application starts, navigate to `http://localhost:8000` in your web browser. On Windows, you may need to navigate to the container via IP address. See [ASP.NET Core apps in Windows Containers](aspnetcore-docker-windows.md) for instructions on determining the IP address, using the value of `--name` that you used in `docker run`.

See [Hosting ASP.NET Core Images with Docker over HTTPS](aspnetcore-docker-https.md) to use HTTPS with this image.

## Getting the sample

Expand Down Expand Up @@ -49,9 +51,11 @@ Now listening on: http://[::]:80
Application started. Press Ctrl+C to shut down.
```

After the application starts, navigate to `http://localhost:8000` in your web browser. You need to navigate to the application via IP address instead of `localhost` for Windows containers, which is demonstrated in the [View the ASP.NET Core app in a running container on Windows](#view-the-aspnet-core-app-in-a-running-container-on-windows) section.
After the application starts, navigate to `http://localhost:8000` in your web browser. On Windows, you may need to navigate to the container via IP address. See [ASP.NET Core apps in Windows Containers](aspnetcore-docker-windows.md) for instructions on determining the IP address, using the value of `--name` that you used in `docker run`.

> Note: The `-p` argument maps port 8000 on your local machine to port 80 in the container (the form of the port mapping is `host:container`). See the [Docker run reference](https://docs.docker.com/engine/reference/commandline/run/) for more information on commandline parameters. In some cases, you might see an error because the host port you select is already in use. Choose a different port in that case.
Note: The `-p` argument maps port 8000 on your local machine to port 80 in the container (the form of the port mapping is `host:container`). See the [Docker run reference](https://docs.docker.com/engine/reference/commandline/run/) for more information on commandline parameters.
## Additional Samples

Multiple variations of this sample have been provided, as follows. Some of these example Dockerfiles are demonstrated later. Specify an alternate Dockerfile via the `-f` argument.

Expand All @@ -60,49 +64,9 @@ Multiple variations of this sample have been provided, as follows. Some of these
* [Nanoserver 2016 SAC sample](Dockerfile.nanoserver-sac2016)
* [Alpine sample](Dockerfile.alpine-x64)

### View the ASP.NET Core app in a running container on Windows

After the ASP.NET Core application starts, navigate to the container IP (as opposed to http://localhost) in your web browser with the the following instructions:

1. Open up another command prompt.
1. Run `docker exec aspnetcore_sample ipconfig`.
1. Copy the container IP address and paste into your browser (for example, `172.29.245.43`).

See the following example of how to get the IP address of a running Windows container.

```console
C:\git\dotnet-docker\samples\aspnetapp>docker exec aspnetcore_sample ipconfig

Windows IP Configuration


Ethernet adapter Ethernet:

Connection-specific DNS Suffix . : contoso.com
Link-local IPv6 Address . . . . . : fe80::1967:6598:124:cfa3%4
IPv4 Address. . . . . . . . . . . : 172.29.245.43
Subnet Mask . . . . . . . . . . . : 255.255.240.0
Default Gateway . . . . . . . . . : 172.29.240.1
```

Note: [`docker exec`](https://docs.docker.com/engine/reference/commandline/exec/) supports identifying containers with name or hash. The container name is used in the preceding instructions. `docker exec` runs a new command (as opposed to the [entrypoint](https://docs.docker.com/engine/reference/builder/#entrypoint)) in a running container.

Some people prefer using `docker inspect` for this same purpose, as demonstrated in the following example.

```console
C:\git\dotnet-docker\samples\aspnetapp>docker inspect -f "{{ .NetworkSettings.Networks.nat.IPAddress }}" aspnetcore_sample
172.25.157.148
```

## Deploying to Production vs Development
## Deploying with HTTPS

The approach for running containers differs between development and production.

In production, you will typically start your container with `docker run -d`. This argument starts the container as a service, without any console interaction. You then interact with it through other Docker commands or APIs exposed by the containerized application.

In development, you will typically start containers with `docker run --rm -it`. These arguments enable you to see a console (important when there are errors), terminate the container with `CTRL-C` and cleans up all container resources when the container is termiantes. You also typically don't mind blocking the console. This approach is demonstrated in prior examples in this document.

We recommend that you do not use `--rm` in production. It cleans up container resources, preventing you from collecting logs that may have been captured in a container that has either stopped or crashed.
ASP.NET Core 2.1 uses [HTTPS by default](https://docs.microsoft.com/en-us/aspnet/core/security/enforcing-ssl). You can [configure ASP.NET Core to use HTTPS with Docker](aspnetcore-docker-https.md).

## Build and run the sample for Alpine X64 with Docker

Expand Down Expand Up @@ -132,6 +96,16 @@ You can build and run the sample for ARM32 and Raspberry Pi with [Build ASP.NET

You can develop applications without a .NET Core installation on your machine with the [Develop ASP.NET Core applications in a container](aspnet-docker-dev-in-container.md) instructions. These instructions are also useful if your development and production environments do not match.

## Deploying to Production vs Development

The approach for running containers differs between development and production.

In production, you will typically start your container with `docker run -d`. This argument starts the container as a service, without any console interaction. You then interact with it through other Docker commands or APIs exposed by the containerized application.

In development, you will typically start containers with `docker run --rm -it`. These arguments enable you to see a console (important when there are errors), terminate the container with `CTRL-C` and cleans up all container resources when the container is termiantes. You also typically don't mind blocking the console. This approach is demonstrated in prior examples in this document.

We recommend that you do not use `--rm` in production. It cleans up container resources, preventing you from collecting logs that may have been captured in a container that has either stopped or crashed.

## Build and run the sample locally

You can build and run the sample locally with the [.NET Core 2.0 SDK](https://www.microsoft.com/net/download/core) using the following commands. The commands assume that you are in the root of the repository.
Expand All @@ -142,7 +116,7 @@ cd aspnetapp
dotnet run
```

After the application starts, visit `http://localhost:8000` in your web browser.
After the application starts, visit `http://localhost:5000` in your web browser.

You can produce an application that is ready to deploy to production locally using the following command.

Expand Down
Loading

0 comments on commit faa0b48

Please sign in to comment.