Adopt PowerShell syntax on Windows (#1584)

* Adopt PowerShell syntax on Windows

* Update samples/complexapp/README.md

Co-Authored-By: Steve Lee <slee@microsoft.com>

* Apply suggestions from code review

Co-Authored-By: Michael Simons <msimons@microsoft.com>

Co-authored-by: Steve Lee <slee@microsoft.com>
Co-authored-by: Michael Simons <msimons@microsoft.com>
This commit is contained in:
Rich Lander 2020-01-15 13:24:27 -08:00 коммит произвёл GitHub
Родитель f966bb638e
Коммит 1511eb5fc2
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
4 изменённых файлов: 103 добавлений и 60 удалений

Просмотреть файл

@ -48,29 +48,52 @@ dotnetapp.dll
## Windows using Linux containers ## Windows using Linux containers
The following example uses PowerShell.
```console ```console
docker run --rm -v %cd%:/app -w /app mcr.microsoft.com/dotnet/core/sdk:3.1 dotnet publish -c release -o out -r win-x64 --self-contained false docker run --rm -v ${pwd}:/app -w /app mcr.microsoft.com/dotnet/core/sdk:3.1 dotnet publish -c release -o out -r win-x64 --self-contained false
```
You can see the built binaries with the following command:
```console
PS C:\git\dotnet-docker\samples\dotnetapp> dir out
Directory: C:\git\dotnet-docker\samples\dotnetapp\out
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a--- 1/14/2020 9:19 PM 449 dotnetapp.deps.json
-a--- 1/14/2020 9:19 PM 7680 dotnetapp.dll
-a--- 1/14/2020 9:19 PM 168448 dotnetapp.exe
-a--- 1/14/2020 9:19 PM 736 dotnetapp.pdb
-a--- 1/14/2020 9:19 PM 146 dotnetapp.runtimeconfig.json
``` ```
## Windows using Windows containers ## Windows using Windows containers
The following example uses PowerShell.
```console ```console
> docker run --rm -v %cd%:c:\app -w c:\app mcr.microsoft.com/dotnet/core/sdk:3.1 dotnet publish -c Release -o out docker run --rm -v ${pwd}:c:\app -w c:\app mcr.microsoft.com/dotnet/core/sdk:3.1 dotnet publish -c Release -o out
>dir out ```
Volume in drive C is Windows
Volume Serial Number is 384B-0B6E
Directory of C:\git\dotnet-docker\samples\dotnetapp\out You can see the built binaries with the following command:
01/14/2020 01:38 PM <DIR> . ```console
01/14/2020 01:38 PM <DIR> .. PS C:\git\dotnet-docker\samples\dotnetapp> dir out
01/14/2020 01:38 PM 419 dotnetapp.deps.json
01/14/2020 01:38 PM 8,192 dotnetapp.dll
01/14/2020 01:38 PM 168,448 dotnetapp.exe Directory: C:\git\dotnet-docker\samples\dotnetapp\out
01/14/2020 01:38 PM 744 dotnetapp.pdb
01/14/2020 01:38 PM 154 dotnetapp.runtimeconfig.json Mode LastWriteTime Length Name
5 File(s) 177,957 bytes ---- ------------- ------ ----
2 Dir(s) 50,011,774,976 bytes free -a--- 1/14/2020 9:25 PM 419 dotnetapp.deps.json
-a--- 1/14/2020 9:25 PM 8192 dotnetapp.dll
-a--- 1/14/2020 9:25 PM 168448 dotnetapp.exe
-a--- 1/14/2020 9:25 PM 744 dotnetapp.pdb
-a--- 1/14/2020 9:25 PM 154 dotnetapp.runtimeconfig.json
``` ```
## Building to a separate location ## Building to a separate location
@ -92,28 +115,29 @@ dotnetapp.deps.json dotnetapp.runtimeconfig.json
dotnetapp.dll dotnetapp.dll
``` ```
The following example demonstrates doing that on Windows (using Linux containers): The following PowerShell example demonstrates doing that on Windows (using Linux containers):
```console ```console
> mkdir C:\dotnetapp mkdir C:\dotnetapp
> docker run --rm -v C:\dotnetapp:/out -v %cd%:/app -w /app mcr.microsoft.com/dotnet/core/sdk:3.1 dotnet publish -c release -o /out -r win-x64 --self-contained false docker run --rm -v C:\dotnetapp:/out -v ${pwd}:/app -w /app mcr.microsoft.com/dotnet/core/sdk:3.1 dotnet publish -c release -o /out -r win-x64 --self-contained false
> dir C:\dotnetapp
Volume in drive C has no label.
Volume Serial Number is 7A9E-EFFE
Directory of C:\dotnetapp
01/14/2020 12:58 PM <DIR> .
01/14/2020 12:58 PM <DIR> ..
01/14/2020 12:58 PM 449 dotnetapp.deps.json
01/14/2020 12:58 PM 7,680 dotnetapp.dll
01/14/2020 12:58 PM 168,448 dotnetapp.exe
01/14/2020 12:58 PM 736 dotnetapp.pdb
01/14/2020 12:58 PM 146 dotnetapp.runtimeconfig.json
5 File(s) 177,459 bytes
2 Dir(s) 106,439,225,344 bytes free
``` ```
You can see the built binaries with the following command:
```console
PS C:\git\dotnet-docker\samples\dotnetapp> dir C:\dotnetapp\
Directory: C:\dotnetapp
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a--- 1/14/2020 9:27 PM 449 dotnetapp.deps.json
-a--- 1/14/2020 9:27 PM 7680 dotnetapp.dll
-a--- 1/14/2020 9:27 PM 168448 dotnetapp.exe
-a--- 1/14/2020 9:27 PM 736 dotnetapp.pdb
-a--- 1/14/2020 9:27 PM 146 dotnetapp.runtimeconfig.json
## More Samples ## More Samples
* [.NET Core Docker Samples](../README.md) * [.NET Core Docker Samples](../README.md)

Просмотреть файл

@ -66,10 +66,10 @@ ENTRYPOINT ["dotnet", "test", "--logger:trx"]
The presence of the `test` stage costs very little and doesn't significantly change the behavior of the build if you don't specifically target it. By default, the test stage `ENTRYPOINT` will not be used if you build this Dockerfile The presence of the `test` stage costs very little and doesn't significantly change the behavior of the build if you don't specifically target it. By default, the test stage `ENTRYPOINT` will not be used if you build this Dockerfile
The following example demonstrates targeting the `test` stage with the `--target` argument, and with logging enabled: The following example demonstrates targeting the `test` stage with the `--target` argument, and with logging enabled, using PowerShell:
```console ```console
C:\git\dotnet-docker\samples\complexapp> docker build --pull --target test -t complexapp-test . PS C:\git\dotnet-docker\samples\complexapp> docker build --pull --target test -t complexapp-test .
Sending build context to Docker daemon 12.81MB Sending build context to Docker daemon 12.81MB
Step 1/15 : FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build Step 1/15 : FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build
3.1: Pulling from dotnet/core/sdk 3.1: Pulling from dotnet/core/sdk
@ -77,9 +77,9 @@ Successfully built f98c5453be3d
Successfully tagged complexapp-test:latest Successfully tagged complexapp-test:latest
SECURITY WARNING: You are building a Docker image from Windows against a non-Windows Docker host. All files and directories added to build context will have '-rwxr-xr-x' permissions. It is recommended to double check and reset permissions for sensitive files and directories. SECURITY WARNING: You are building a Docker image from Windows against a non-Windows Docker host. All files and directories added to build context will have '-rwxr-xr-x' permissions. It is recommended to double check and reset permissions for sensitive files and directories.
C:\git\dotnet-docker\samples\complexapp>mkdir TestResults PS C:\git\dotnet-docker\samples\complexapp> mkdir TestResults
C:\git\dotnet-docker\samples\complexapp>docker run --rm -v %cd%/TestResults:/source/tests/TestResults complexapp-test PS C:\git\dotnet-docker\samples\complexapp> docker run --rm -v $pwd/TestResults:/source/tests/TestResults complexapp-test
Test run for /source/tests/bin/Debug/netcoreapp3.1/tests.dll(.NETCoreApp,Version=v3.1) Test run for /source/tests/bin/Debug/netcoreapp3.1/tests.dll(.NETCoreApp,Version=v3.1)
Microsoft (R) Test Execution Command Line Tool Version 16.3.0 Microsoft (R) Test Execution Command Line Tool Version 16.3.0
Copyright (c) Microsoft Corporation. All rights reserved. Copyright (c) Microsoft Corporation. All rights reserved.
@ -94,15 +94,14 @@ Total tests: 2
Passed: 2 Passed: 2
Total time: 1.8321 Seconds Total time: 1.8321 Seconds
C:\git\dotnet-docker\samples\complexapp>dir TestResults PS C:\git\dotnet-docker\samples\complexapp> dir .\TestResults\
Volume in drive C is Windows
Volume Serial Number is 384B-0B6E
Directory of C:\git\dotnet-docker\samples\complexapp\TestResults
12/19/2019 03:48 PM <DIR> . Directory: C:\git\dotnet-docker\samples\complexapp\TestResults
12/19/2019 03:48 PM <DIR> ..
12/19/2019 03:48 PM 3,635 _fd11ea307347_2019-12-19_23_48_20.trx Mode LastWriteTime Length Name
---- ------------- ------ ----
-a--- 1/14/2020 9:33 PM 3635 _c4f066aca651_2020-01-15_05_33_22.trx
``` ```
The [run-test-stage.ps1](run-test-stage.ps1) [PowerShell](https://github.com/powershell/powershell) script implements the same workflow. It may be easier to understand the workflow by reading and running the script. The [run-test-stage.ps1](run-test-stage.ps1) [PowerShell](https://github.com/powershell/powershell) script implements the same workflow. It may be easier to understand the workflow by reading and running the script.
@ -112,22 +111,26 @@ The following instructions demonstrate this scenario in various configurations,
### Linux or macOS ### Linux or macOS
```console ```console
$ docker build --pull --target test -t complexapp-test . docker build --pull --target test -t complexapp-test .
$ docker run --rm -v $(pwd)/TestResults:/source/tests/TestResults complexapp-test docker run --rm -v ${pwd}/TestResults:/source/tests/TestResults complexapp-test
``` ```
### Windows using Linux containers ### Windows using Linux containers
The following example uses PowerShell.
```console ```console
>docker build --pull --target test -t complexapp-test . docker build --pull --target test -t complexapp-test .
>docker run --rm -v %cd%/TestResults:/source/tests/TestResults complexapp-test docker run --rm -v ${pwd}/TestResults:/source/tests/TestResults complexapp-test
``` ```
### Windows using Windows containers ### Windows using Windows containers
The following example uses PowerShell.
```console ```console
>docker build --pull --target test -t complexapp-test . docker build --pull --target test -t complexapp-test .
>docker run --rm -v %cd%/TestResults:c:\source\tests\TestResults complexapp-test docker run --rm -v ${pwd}/TestResults:c:\source\tests\TestResults complexapp-test
``` ```
## Running tests while building an image ## Running tests while building an image

Просмотреть файл

@ -85,14 +85,18 @@ docker run --rm -it -v $(pwd):/app/ -w /app mcr.microsoft.com/dotnet/core/sdk:3.
## Windows using Linux containers ## Windows using Linux containers
This example uses PowerShell.
```console ```console
docker run --rm -it -v %cd%:/app/ -w /app mcr.microsoft.com/dotnet/core/sdk:3.1 dotnet run docker run --rm -it -v ${pwd}:/app/ -w /app mcr.microsoft.com/dotnet/core/sdk:3.1 dotnet run
``` ```
## Windows using Windows containers ## Windows using Windows containers
This example uses PowerShell.
```console ```console
docker run --rm -it -v %cd%:c:\app\ -w \app mcr.microsoft.com/dotnet/core/sdk:3.1 dotnet run docker run --rm -it -v ${pwd}:c:\app\ -w \app mcr.microsoft.com/dotnet/core/sdk:3.1 dotnet run
``` ```
## ASP.NET Core App ## ASP.NET Core App
@ -128,14 +132,18 @@ docker run --rm -it -p 8000:80 -v $(pwd):/app/ -w /app -e ASPNETCORE_URLS=http:/
### Windows using Linux containers ### Windows using Linux containers
This example uses PowerShell.
```console ```console
docker run --rm -it -p 8000:80 -v %cd%:/app/ -w /app -e ASPNETCORE_URLS=http://+:80 -e ASPNETCORE_ENVIRONMENT=Development mcr.microsoft.com/dotnet/core/sdk:3.1 dotnet run --no-launch-profile docker run --rm -it -p 8000:80 -v ${pwd}:/app/ -w /app -e ASPNETCORE_URLS=http://+:80 -e ASPNETCORE_ENVIRONMENT=Development mcr.microsoft.com/dotnet/core/sdk:3.1 dotnet run --no-launch-profile
``` ```
### Windows using Windows containers ### Windows using Windows containers
This example uses PowerShell.
```console ```console
docker run --rm -it -p 8000:80 -v %cd%:C:\app\ -w /app -e ASPNETCORE_URLS=http://+:80 -e ASPNETCORE_ENVIRONMENT=Development mcr.microsoft.com/dotnet/core/sdk:3.1 dotnet run --no-launch-profile docker run --rm -it -p 8000:80 -v ${pwd}:C:\app\ -w /app -e ASPNETCORE_URLS=http://+:80 -e ASPNETCORE_ENVIRONMENT=Development mcr.microsoft.com/dotnet/core/sdk:3.1 dotnet run --no-launch-profile
``` ```
### Using a launch profile to configure ASP.NET Core ### Using a launch profile to configure ASP.NET Core
@ -165,14 +173,18 @@ docker run --rm -it -p 8000:80 -v $(pwd):/app -w /app mcr.microsoft.com/dotnet/c
### Windows using Linux containers ### Windows using Linux containers
The following example uses PowerShell.
```console ```console
docker run --rm -it -p 8000:80 -v %cd%:/app -w /app mcr.microsoft.com/dotnet/core/sdk:3.1 dotnet run --launch-profile container docker run --rm -it -p 8000:80 -v ${pwd}:/app -w /app mcr.microsoft.com/dotnet/core/sdk:3.1 dotnet run --launch-profile container
``` ```
### Windows using Windows containers ### Windows using Windows containers
The following example uses PowerShell.
```console ```console
docker run --rm -it -p 8000:80 -v %cd%:C:\app -w C:\app mcr.microsoft.com/dotnet/core/sdk:3.1 dotnet run --launch-profile container docker run --rm -it -p 8000:80 -v ${pwd}:C:\app -w C:\app mcr.microsoft.com/dotnet/core/sdk:3.1 dotnet run --launch-profile container
``` ```
## More Samples ## More Samples

Просмотреть файл

@ -26,10 +26,10 @@ curl -o Directory.Build.props https://raw.githubusercontent.com/dotnet/dotnet-do
## Running tests ## Running tests
The easiest approach is to run `dotnet test` within a .NET Core SDK container using the following pattern, with `docker run` and volume mounting. This initial example is demonstrated on Windows (in Linux container mode). Instructions for all OSes follow. The easiest approach is to run `dotnet test` within a .NET Core SDK container using the following pattern, with `docker run` and volume mounting. This initial example is demonstrated on Windows with PowerShell (in Linux container mode). Instructions for all OSes follow.
```console ```console
> docker run --rm -v %cd%:/app -w /app/tests mcr.microsoft.com/dotnet/core/sdk:3.1 dotnet test > docker run --rm -v ${pwd}:/app -w /app/tests mcr.microsoft.com/dotnet/core/sdk:3.1 dotnet test
Test run for /app/tests/bin/Debug/netcoreapp3.1/tests.dll(.NETCoreApp,Version=v3.1) Test run for /app/tests/bin/Debug/netcoreapp3.1/tests.dll(.NETCoreApp,Version=v3.1)
Microsoft (R) Test Execution Command Line Tool Version 16.3.0 Microsoft (R) Test Execution Command Line Tool Version 16.3.0
Copyright (c) Microsoft Corporation. All rights reserved. Copyright (c) Microsoft Corporation. All rights reserved.
@ -60,14 +60,18 @@ docker run --rm -v $(pwd):/app -w /app/tests mcr.microsoft.com/dotnet/core/sdk:3
### Windows using Linux containers ### Windows using Linux containers
This example uses PowerShell.
```console ```console
docker run --rm -v %cd%:/app -w /app/tests mcr.microsoft.com/dotnet/core/sdk:3.1 dotnet test --logger:trx docker run --rm -v ${pwd}:/app -w /app/tests mcr.microsoft.com/dotnet/core/sdk:3.1 dotnet test --logger:trx
``` ```
### Windows using Windows containers ### Windows using Windows containers
This example uses PowerShell.
```console ```console
docker run --rm -v %cd%:C:\app -w C:\app\tests mcr.microsoft.com/dotnet/core/sdk:3.1 dotnet test --logger:trx docker run --rm -v ${pwd}:C:\app -w C:\app\tests mcr.microsoft.com/dotnet/core/sdk:3.1 dotnet test --logger:trx
``` ```
## More Samples ## More Samples