Difference between revisions of "StaffFinder Diary"

From Logic Wiki
Jump to: navigation, search
Line 54: Line 54:
 
  docker build -t stafffinder.api
 
  docker build -t stafffinder.api
 
  docker run -d -p 8080:80 --name myapp stafffinder.api
 
  docker run -d -p 8080:80 --name myapp stafffinder.api
Go to [http://localhost:8080/api/values http://localhost:8080/api/values]
+
Go to [http://localhost:8080/api/values http://localhost:8080/api/values] and same api values are still there.
 +
 
 +
docker images
 +
to list docker images in your computer

Revision as of 01:19, 17 December 2017


In a Mac computer download and install all prerequisites below:

  • Dotnet Core SDK
  • Visual Studio Code
  • Node / Angular
  • Git
  • Docker

Starting a new Project

Creating a new dotnet core web api project

dotnet new webapi -o StaffFinder.Api -n StaffFinder.Api
cd StaffFinder.Api
dotnet build
dotnet run 

When I browse http://localhost:5000/api/values I can see test json object

[
"value1",
"value2"
]

Adding docker support

Create a Dockerfile for an ASP.NET Core application

  • Create a Dockerfile in your project folder. it's case sensitive
  • Add the text below to your Dockerfile
FROM microsoft/aspnetcore-build:2.0 AS build-env
WORKDIR /app
# Copy csproj and restore as distinct layers
COPY *.csproj ./
RUN dotnet restore

# Copy everything else and build
COPY . ./
RUN dotnet publish -c Release -o out

# Build runtime image
FROM microsoft/aspnetcore:2.0
WORKDIR /app
COPY --from=build-env /app/out .
ENTRYPOINT ["dotnet", "StaffFinder.Api.dll"]

To make your build context as small as possible add a .dockerignore file to your project folder and copy the following into it.

bin\
obj\

Build and run the Docker image

In the command prompt and navigate to your project folder.

Use the following commands to build and run your Docker image:

docker build -t stafffinder.api
docker run -d -p 8080:80 --name myapp stafffinder.api

Go to http://localhost:8080/api/values and same api values are still there.

docker images 

to list docker images in your computer