09 February 2017

.Net Core and Docker

Docker Notes taken from Building Docker Images for .NET Core

Install

* Install: npm install -g yo generator-aspnet generator-docker
* Help: docker help


Starting New Project

See: https://docs.microsoft.com/en-us/aspnet/core/tutorials/your-first-mac-aspnet
* npm install -g yo generator-aspnet
* yo aspnet
* Select application type e.g. Web Application Basic [without Membership and Authorization]
* Enter a name


Setup API project 

Run on localhost:5000 by default


Add Docker Support

* yo docker
* Answer:
  * Language: .Net Core
  * Version: rtm
  * WebServer: y
  * Port: 5000
  * Image Name: [ProjectName]
  * Service: [ProjectName]
  * Compose: [ProjectName]
  * Overwrite: Y

Adds the following files:
* Dockerfile.debug - based on the microsoft/dotnet:1.0.0-preview2-sdk
  Used for development/debug
* Dockerfile - based on microsoft/dotnet:1.0.0-core
  Used for Release

Build Docker Images

NB: I had to:

  • Amend the standard .sh file to use .NetCore1.1 (not 1.0)
  • Amend the Dockerfile.debug:
    • Use 1.1:
      FROM microsoft/dotnet:1.1.0-sdk-projectjson
    • Include a line to install unzip:
      RUN apt-get update && apt-get install -y unzip && rm -rf /var/lib/apt/lists/*
      before RUN curl
  • Amend DockerFile to use 1.1:
    FROM microsoft/dotnet:1.1.0-runtime
*  Build Debug image from Dockerfile.debug
   ./dockertask.sh build debug
*  Build Release image from Dockerfile
  ./dockertask.sh build release

Run

* docker run -d -p 5000:5000 [image name]:[tag name]
* Load in browser: e.g. http://localhost:5000/api/values

Docker Images/Containers

* Cleanup:
  docker system prune

Images
* List:
  docker images
* Delete
  docker rmi [the image ID]
* Delete 'Dangling' i.e. without tags:
  docker rmi $(docker images -qf "dangling=true")

Containers
* List:
  docker ps -a
* Remove all existing containers (not images!):
  docker rm $(docker ps -a -q)
* Kill all containers and remove them:
  docker rm $(docker kill $(docker ps -aq))

No comments:

Post a Comment