https://github.com/neilkuan/dotnet-webapi
test docker build to image
https://github.com/neilkuan/dotnet-webapi
Last synced: about 2 months ago
JSON representation
test docker build to image
- Host: GitHub
- URL: https://github.com/neilkuan/dotnet-webapi
- Owner: neilkuan
- Created: 2019-07-25T07:46:59.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2019-07-26T05:47:37.000Z (almost 6 years ago)
- Last Synced: 2025-03-29T02:38:26.133Z (2 months ago)
- Language: C#
- Size: 164 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# dotnet source to code
首先 clone git 專案$ git clone https://github.com/guan840912/dotnet-webapi.git
on master 會有 dockerfile 和 webapilab1 資料夾
#dockerfile
===========================================================================
FROM mcr.microsoft.com/dotnet/core/sdk:latest
COPY ./webapilab1 /app/
WORKDIR /app/bin/Debug/netcoreapp2.2
CMD [ "sh", "-c", "dotnet webapilab1.dll" ]
===========================================================================
主要去從docker hub pull dotnet image

複製與dockerfile同一格資料夾下的 webapilab1 內的檔案or 資料夾 複製到 image 內的 /app/ 裡面
給與container 啟動後的工作資料夾
執行 `dotnet webapilab1.dll`故clone 專案下來後 (環境要有 git 和 docker)
#進入專案資料夾
$ cd dotnet-webapi/
#build docker image and tag it , . 是指當下資料夾的dockerfile
$ docker build -t dotnetwebapi:0.1 .
#docker images 顯示所有的images名稱為dotnetwebapi
$ docker image ls -a dotnetwebapi
#執行 docker run 指令 --name 給container name ,--rm container stop 就刪除 ,dotnetwebapi:0.1 image name
$ docker run --name dotwebapi -p 8000:80 --rm dotnetwebapi:0.1
#執行後前端的terminal 會被吃掉 (如果不想被吃掉,可以在docker run 時 run 參數的後面加上 -d 參數<在背景執行>)像下面:
$ docker run -d --name dotwebapi -p 8000:80 --rm dotnetwebapi:0.1
#現在我們可以訪問我們docker host 的 ip 的 8000 port
http://:8000/api/values/5555
or (on docker host terminal)
$ curl -s http://localhost:8000/api/values/555556 ; echo ""
#<變數> <; echo 只是為了排版好看>

#如果terminal 畫面沒有終止,將可以看到訪問logs
#如果想終止,只需開啟另一個 terminal stop container
$ docker container stop dotwebapi
#查看正在執行的container
$ docker container ls


----------
## 所以如果當developer 開發