Size: 6596
Comment:
|
Size: 7006
Comment:
|
Deletions are marked like this. | Additions are marked like this. |
Line 200: | Line 200: |
=== Docker commands === {{{#!highlight bash #build image docker build -t dotnetcorehello . # execute bash in running container docker exec -it $1 bash # delete all containers docker ps -a | awk '//{print $1}' | grep -v "CONTAINER" | xargs -i sh -c 'docker stop {};docker rm {}' # execute container using inage dotnetcorehello docker run -d dotnetcorehello # list all containers docker ps -a }}} |
.Net core
.NET Core to develop console or Web applications. .NET Core is a set of runtime, library and compiler components that allow you to create apps that run on Windows, macOS and Linux.
https://docs.microsoft.com/pt-pt/dotnet/core/docker/building-net-docker-images
https://msdn.microsoft.com/en-us/library/ff361664(v=vs.110).aspx
Sample hello world
. ├── appSolution.sln ├── Dockerfile ├── myApp │ ├── myApp.csproj │ └── Program.cs ├── myLib │ ├── Class1.cs │ └── myLib.csproj ├── myLibTests │ ├── myLibTests.csproj │ └── UniTest1.cs
Dockerfile
FROM microsoft/dotnet:2.0-sdk WORKDIR /app RUN apt-get update RUN apt-get install net-tools procps vim nano -y RUN mkdir -p /app/myApp RUN mkdir -p /app/myLib RUN mkdir -p /app/myLibTests ADD myApp/* /app/myApp/ ADD myLib/* /app/myLib/ ADD myLibTests/* /app/myLibTests/ ADD appSolution.sln /app/ RUN cd /app && dotnet clean && dotnet build RUN cd /app/myLibTests && dotnet clean && dotnet test CMD cd /app/myApp/ && dotnet bin/Debug/netcoreapp2.0/myApp.dll && tail -f /var/log/lastlog #CMD tail -f /var/log/lastlog
appSolution.sln
Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 15 VisualStudioVersion = 15.0.26124.0 MinimumVisualStudioVersion = 15.0.26124.0 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "myApp", "myApp\myApp.csproj", "{5E009AC4-9BF5-4E1B-9C22-377AC9ECC4EB}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "myLib", "myLib\myLib.csproj", "{00D6703F-2D64-4D9A-95AA-430DC38E4EC3}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU Debug|x64 = Debug|x64 Debug|x86 = Debug|x86 Release|Any CPU = Release|Any CPU Release|x64 = Release|x64 Release|x86 = Release|x86 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution {5E009AC4-9BF5-4E1B-9C22-377AC9ECC4EB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {5E009AC4-9BF5-4E1B-9C22-377AC9ECC4EB}.Debug|Any CPU.Build.0 = Debug|Any CPU {5E009AC4-9BF5-4E1B-9C22-377AC9ECC4EB}.Debug|x64.ActiveCfg = Debug|x64 {5E009AC4-9BF5-4E1B-9C22-377AC9ECC4EB}.Debug|x64.Build.0 = Debug|x64 {5E009AC4-9BF5-4E1B-9C22-377AC9ECC4EB}.Debug|x86.ActiveCfg = Debug|x86 {5E009AC4-9BF5-4E1B-9C22-377AC9ECC4EB}.Debug|x86.Build.0 = Debug|x86 {5E009AC4-9BF5-4E1B-9C22-377AC9ECC4EB}.Release|Any CPU.ActiveCfg = Release|Any CPU {5E009AC4-9BF5-4E1B-9C22-377AC9ECC4EB}.Release|Any CPU.Build.0 = Release|Any CPU {5E009AC4-9BF5-4E1B-9C22-377AC9ECC4EB}.Release|x64.ActiveCfg = Release|x64 {5E009AC4-9BF5-4E1B-9C22-377AC9ECC4EB}.Release|x64.Build.0 = Release|x64 {5E009AC4-9BF5-4E1B-9C22-377AC9ECC4EB}.Release|x86.ActiveCfg = Release|x86 {5E009AC4-9BF5-4E1B-9C22-377AC9ECC4EB}.Release|x86.Build.0 = Release|x86 {00D6703F-2D64-4D9A-95AA-430DC38E4EC3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {00D6703F-2D64-4D9A-95AA-430DC38E4EC3}.Debug|Any CPU.Build.0 = Debug|Any CPU {00D6703F-2D64-4D9A-95AA-430DC38E4EC3}.Debug|x64.ActiveCfg = Debug|x64 {00D6703F-2D64-4D9A-95AA-430DC38E4EC3}.Debug|x64.Build.0 = Debug|x64 {00D6703F-2D64-4D9A-95AA-430DC38E4EC3}.Debug|x86.ActiveCfg = Debug|x86 {00D6703F-2D64-4D9A-95AA-430DC38E4EC3}.Debug|x86.Build.0 = Debug|x86 {00D6703F-2D64-4D9A-95AA-430DC38E4EC3}.Release|Any CPU.ActiveCfg = Release|Any CPU {00D6703F-2D64-4D9A-95AA-430DC38E4EC3}.Release|Any CPU.Build.0 = Release|Any CPU {00D6703F-2D64-4D9A-95AA-430DC38E4EC3}.Release|x64.ActiveCfg = Release|x64 {00D6703F-2D64-4D9A-95AA-430DC38E4EC3}.Release|x64.Build.0 = Release|x64 {00D6703F-2D64-4D9A-95AA-430DC38E4EC3}.Release|x86.ActiveCfg = Release|x86 {00D6703F-2D64-4D9A-95AA-430DC38E4EC3}.Release|x86.Build.0 = Release|x86 EndGlobalSection EndGlobal
myApp/Program.cs
using System; using myLib; namespace myApp { class Program { static void Main(string[] args) { Console.WriteLine( Class1.getHelloWorld() ); } } }
myApp/myApp.csproj
<Project Sdk="Microsoft.NET.Sdk"> <ItemGroup> <ProjectReference Include="..\myLib\myLib.csproj" /> </ItemGroup> <PropertyGroup> <OutputType>Exe</OutputType> <TargetFramework>netcoreapp2.0</TargetFramework> </PropertyGroup> </Project>
myLib/Class1.cs
using System; namespace myLib { public class Class1 { public static String getHelloWorld() { return "Hello world from library."; } } }
myLib/myLib.csproj
<Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <TargetFramework>netstandard2.0</TargetFramework> </PropertyGroup> </Project>
myLibTests/UniTest1.cs
using System; using Xunit; using myLib; namespace myLibTests { public class UnitTest1 { [Fact] public void Test1() { Assert.Equal("Hello world from library." , Class1.getHelloWorld() ); } } }
myLibTests/myLibTests.csproj
<Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <TargetFramework>netcoreapp2.0</TargetFramework> <IsPackable>false</IsPackable> </PropertyGroup> <ItemGroup> <PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.6.0" /> <PackageReference Include="xunit" Version="2.3.1" /> <PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" /> <DotNetCliToolReference Include="dotnet-xunit" Version="2.3.1" /> </ItemGroup> <ItemGroup> <ProjectReference Include="..\myLib\myLib.csproj" /> </ItemGroup> </Project>
Docker commands
1 #build image
2 docker build -t dotnetcorehello .
3 # execute bash in running container
4 docker exec -it $1 bash
5 # delete all containers
6 docker ps -a | awk '//{print $1}' | grep -v "CONTAINER" | xargs -i sh -c 'docker stop {};docker rm {}'
7 # execute container using inage dotnetcorehello
8 docker run -d dotnetcorehello
9 # list all containers
10 docker ps -a