StaffFinder Diary
In a Mac computer download and install all prerequisites below:
- Dotnet Core SDK
- Visual Studio Code
- Node / Angular
- Git
- Docker
Contents
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
Pushing docker image to Hub (Canister.io)
Start by logging in:
docker login --username=username cloud.canister.io:5000
The next step is to tag an image that you want to publish:
docker tag ae5da82730b1 cloud.canister.io:5000/username/my-repo:latest
Notice the format of the tag: <registry-url-including-port>/<username>/<repo-name>:<tag>. I used latest as my tag name but you can use any tag name you want.
Finally we just need to push the tag:
docker push cloud.canister.io:5000/username/my-repo
Note that this command doesn’t include the tag being pushed. It will push all tags in the given repo.
For the deploy I had to do something similar. First, log in to canister.io in the production server:
docker login --username=username cloud.canister.io:5000
Pull the image:
docker pull cloud.canister.io:5000/username/my-repo:latest
And finally start it:
docker run -d --restart=on-failure --name my-service-container cloud.canister.io:5000/username/my-repo:latest