├── .gitignore ├── Dockerfile ├── LICENSE ├── NuGet.Config ├── Program.cs ├── ReadMe.md ├── Startup.cs ├── project.json ├── project.lock.json └── wwwroot └── hello.html /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | bin 3 | obj -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | # NOTE: A project.lock.json file must be included, otherwise you will get the following error: 2 | # Project app does not have a lock file 3 | 4 | # Build the image: 5 | # docker build -t tonysneed/dotnet-helloweb . 6 | 7 | # Create and run a container: 8 | # docker run -d -p 5000:5000 --name dotnet-helloweb -v "${PWD}:/app" tonysneed/dotnet-helloweb 9 | 10 | FROM tonysneed/dotnet-preview:1.0.0-rc2-002673 11 | 12 | MAINTAINER Anthony Sneed 13 | 14 | # Set environment variables 15 | ENV ASPNETCORE_URLS="http://*:5000" 16 | ENV ASPNETCORE_ENVIRONMENT="Staging" 17 | 18 | # Copy files to app directory 19 | COPY . /app 20 | 21 | # Set working directory 22 | WORKDIR /app 23 | 24 | # Restore NuGet packages 25 | RUN ["dotnet", "restore"] 26 | 27 | # Open up port 28 | EXPOSE 5000 29 | 30 | # Run the app 31 | ENTRYPOINT ["dotnet", "run"] -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Anthony Sneed 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /NuGet.Config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Program.cs: -------------------------------------------------------------------------------- 1 | using System.IO; 2 | using Microsoft.AspNetCore.Hosting; 3 | using Microsoft.Extensions.Configuration; 4 | 5 | namespace HelloWeb 6 | { 7 | public class Program 8 | { 9 | public static void Main(string[] args) 10 | { 11 | // Get environment variables 12 | var config = new ConfigurationBuilder() 13 | .AddEnvironmentVariables("") 14 | .Build(); 15 | var url = config["ASPNETCORE_URLS"] ?? "http://*:5000"; 16 | var env = config["ASPNETCORE_ENVIRONMENT"] ?? "Development"; 17 | 18 | var host = new WebHostBuilder() 19 | .UseKestrel() 20 | .UseUrls(url) 21 | .UseEnvironment(env) 22 | .UseContentRoot(Directory.GetCurrentDirectory()) 23 | .UseStartup() 24 | .Build(); 25 | host.Run(); 26 | } 27 | } 28 | } -------------------------------------------------------------------------------- /ReadMe.md: -------------------------------------------------------------------------------- 1 | # DotNet Core Docker Demo 2 | 3 | 1. First install **Docker Toolbox**: https://www.docker.com/products/docker-toolbox 4 | 5 | 2. Build an image based on the latest .NET CLI bits 6 | 7 | ``` 8 | cd Demo.DotNetCoreDocker 9 | docker build -t tonysneed/dotnet-helloweb . 10 | ``` 11 | 12 | 3. Create and run a Docker container based on the image 13 | 14 | ``` 15 | docker run -d -p 5000:5000 --name dotnet-helloweb -v "${PWD}:/app" tonysneed/dotnet-helloweb 16 | ``` 17 | 18 | 4. Open a browser: `http://192.168.99.100:5000` 19 | - You should see: **Hello World!** 20 | 21 | 5. Open a browser: `http://192.168.99.100:5000/hello.html` 22 | - You should see: **Hello from ASP.NET Core!** 23 | - Change the message in wwwroot/hello.html 24 | - Refresh the browser to see the updated message 25 | 26 | 27 | -------------------------------------------------------------------------------- /Startup.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Builder; 2 | using Microsoft.AspNetCore.Hosting; 3 | using Microsoft.AspNetCore.Http; 4 | 5 | namespace HelloWeb 6 | { 7 | public class Startup 8 | { 9 | public void Configure(IApplicationBuilder app) 10 | { 11 | app.UseStaticFiles(); 12 | 13 | app.Run(context => 14 | { 15 | return context.Response.WriteAsync("Hello World!"); 16 | }); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /project.json: -------------------------------------------------------------------------------- 1 | { 2 | "buildOptions": { 3 | "emitEntryPoint": true, 4 | "debugType": "portable" 5 | }, 6 | "dependencies" : { 7 | "Microsoft.AspNetCore.Server.Kestrel": "1.0.0-*", 8 | "Microsoft.AspNetCore.StaticFiles": "1.0.0-*", 9 | "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0-*", 10 | "Microsoft.NETCore.App": { 11 | "type": "platform", 12 | "version": "1.0.0-*" 13 | } 14 | }, 15 | "frameworks": { 16 | "netcoreapp1.0": { 17 | "imports": [ 18 | "portable-net45+wp80+win8+wpa81+dnxcore50", 19 | "portable-net451+win8" 20 | ] 21 | } 22 | }, 23 | "tools": { 24 | }, 25 | "scripts": { 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /wwwroot/hello.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | Home Page 4 | 5 | 6 |

Home Page

7 |

Hello from ASP.NET Core!

8 | 9 | --------------------------------------------------------------------------------