目前憑證效期都只有一年所以會常常用
今天看了上次的做法因沒寫得很仔細,所以又多花了很多時間重新研究
這次做成圖片版的希望明年不用花那麼多時間
下列方法新買的跟舊的均可使用
1-1.到ssls.com網站後點選MY SSL至下圖後點選REISSUE(新購買可能不一樣)
1-2.或是點選REACTIVATE(2023新增),操作後直接跳3
2.點選ONWARDS
3.選擇Use my CSR 然後選擇Windows ,將CREATE CSR...內容文字複製起來
4.到主機上打開命令提示字元(CMD)管理員執行,點確定
5.完成後會出現Begin NNEW至END NEW,將內容複製起來
6.回到網頁中貼在ENTER CSR下方框框後點選ONWARDS
7.選擇您的驗證方式,個人覺得EMAIL跟DNS蠻方便的,就看您有哪種權限
8.使用DNS驗證(Create a DNS record),點選上面選MY SSL,點選GET CNAME
9.在自己的DNS上面新增SSLS.com給的值
10.等待驗證秒數
11.下載SSL檔案
12.會有三個檔案ca-bundle、crt、p7b
13.將三個檔案放在主機中,開啟IIS點選伺服器憑證,點選完成憑證要求,選擇.crt檔
14.完成憑證,如果關掉IIS後再開啟憑證,如果消失了代表沒成功可能要重做看看
2022年8月15日 星期一
2022年6月21日 星期二
Javascript 上個月、本月、下個月
參考了網路寫了一個可直接設定第一天跟最後一天
Format JavaScript date as yyyy-mm-dd
取得當月第一天和最後一天
//上個月
$(document).on('click', '#LastMonth', function () {
SetLastAndFirstDate($('#fromdate').val(), -1);
})
//本月
$(document).on('click', '#ThisMonth', function () {
SetLastAndFirstDate($('#fromdate').val(), 0);
})
//下個月
$(document).on('click', '#NextMonth', function () {
SetLastAndFirstDate($('#fromdate').val(), +1);
})
function SetLastAndFirstDate(nowday, tomonth) {
var date = new Date(nowday);
if (tomonth == 0)
var date = new Date();
var firstDay = new Date(date.getFullYear(), date.getMonth() + (0 + tomonth), 1);
var lastDay = new Date(date.getFullYear(), date.getMonth() + (1+tomonth), 0);
$('#fromdate').val(formatDate(firstDay));//設定第一天
$('#todate').val(formatDate(lastDay));//設定最後一天
}
function formatDate(date) {
var d = new Date(date),
month = '' + (d.getMonth() + 1),
day = '' + d.getDate(),
year = d.getFullYear();
if (month.length < 2)
month = '0' + month;
if (day.length < 2)
day = '0' + day;
return [year, month, day].join('-');
}
參考來源Format JavaScript date as yyyy-mm-dd
取得當月第一天和最後一天
2022年2月10日 星期四
c# ViewModel To Model
這方法也是今天才發現
但真的還蠻實用的
如下兩個Class,StaffViewModel繼承了Staff
就需要轉換目前網路上看最多人推之一AutoMapper
後來發現如果有繼承關係在時被繼承的List中可直接塞入繼承類別如下
真的可以省下很多時間減少安裝插件後的問題
但真的還蠻實用的
如下兩個Class,StaffViewModel繼承了Staff
public class Staff
{
public int id { get; set; }
public string name { get; set; }
}
public class StaffViewModel :Staff
{
public int departid { get; set; }
}
如果後端存檔時前端回傳是StaffViewModel但存檔只需要Staff資料就需要轉換目前網路上看最多人推之一AutoMapper
後來發現如果有繼承關係在時被繼承的List中可直接塞入繼承類別如下
private List<Staff> Merge(List<StaffViewModel> model)
{
List<Staff> result = new List<Staff>(0);
foreach (var item in model)
result.Add(item);
return result;
}
如果以上不是BUG的話設計時能多用原本存在的方式就能少裝些插件真的可以省下很多時間減少安裝插件後的問題
2022年1月21日 星期五
c# DirectoryInfo應用
DirectoryInfo di = new DirectoryInfo(@"\\192.168.0.1\old");
//所有檔案列表包含子資料夾
var queryfileall = di.GetFiles("*", SearchOption.AllDirectories);
//指定單一副檔名
var queryfileone = di.GetFiles("*.jpg", SearchOption.AllDirectories);
//指定多重副檔名
string[] extensions = new[] { ".jpg", ".mp3"};
var queryfilemultiple = di.GetFiles("*", SearchOption.AllDirectories).Where(x => extensions.Contains(x.Extension.ToLower())).ToArray();
//建立資料夾
string newpath = @"\\192.168.0.1\new";
if (!Directory.Exists(newpath))
{
Directory.CreateDirectory(newpath);
}
foreach (var item in queryfile)
{
try
{
//可自行變化...
//複製檔案
if (!File.Exists(newpath + item.Name))
item.MoveTo(newpath + item.Name);
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
//方法2
DirectoryInfo root = new DirectoryInfo(@"\\192.168.0.1\old");
FileInfo[] files = root.GetFiles();
foreach (var item in files)
{}
參考來源Get multiple files with different extension
2021年11月24日 星期三
Python Django APP(8)
在之前學習裡有語法是新增專案的
終端機下輸入
接著在Staff下的views.py新增一個function
必須註冊APP
在setting.py中修改
django-admin.py startproject website在Django還有很重要的就是APP,一個專案可由很多APP組成,APP可多個專案互相使用,所以寫出一個好的APP給專案通用是相當重要的
終端機下輸入
python manage.py startapp staff產生出Staff的APP
接著在Staff下的views.py新增一個function
def staffhello(request,name):
return render(request, 'staff_hello.html', {"hello_str": "你好啊{name},這是來自Staff APP!!".format(name=name)})
staff下新增一個templates資料夾,然後再新增一個staff_hello.html
<!DOCTYPE html>
<html>
<head>
<title>staff_hello</title>
</head>
<body>
<h1>{{ hello_str }}</h1>
</body>
</html>
修改website底下的urls.py
from staff.views import staffhello
urlpatterns = [
path("staff/<str:name>",staffhello),
]
重點來了上述做完後如果網站跑起來會有錯誤必須註冊APP
在setting.py中修改
#原本
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]
#修改後
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'staff',
]
2021年11月22日 星期一
Python Django Template 語法(7)
在template中的註解
{# template中的註解寫法單行 #}
{% comment %}
template中的註解寫法多行
{% endcomment %}
if esle
{% if xxx == 5 %}
{% elif xxx > 4 %}
{% else %}
{% endif %}
for迴圈
{% for xxx in result%}
{% comment %}
以下內容可試看看
forloop.counter0
forloop.counter
forloop.revcounter
forloop.revcounter0
forloop.first
forloop.last
{% endcomment %}
{{forloop.counter}}
{% empty %}
無資料!!
{% endfor %}
2021年11月18日 星期四
Python Django Template(6)
承上篇路徑跟view已經可以搭配了
但這樣畫面看起來就只有文字
所以要搭配html在瀏覽器上看起來才會比較正常
首先要回到settings.py找到如下
在views.py中寫入function來回傳內容
內容自訂主要使用h1標籤來看是否有套版
http://127.0.0.1:8000/hello
參考來源
Templates · Django Girls 學習指南
但這樣畫面看起來就只有文字
所以要搭配html在瀏覽器上看起來才會比較正常
首先要回到settings.py找到如下
#系統預設
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
#修改成
import os
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates').replace('\\', '/')],#templete路徑
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
新增一個templates的資料夾在views.py中寫入function來回傳內容
from django.shortcuts import render
def hello(request):
return render(request, 'hello.html', {"hello_str": "你好啊!!"})
在templates的資料夾中新增一個hello.html內容自訂主要使用h1標籤來看是否有套版
<!DOCTYPE html>
<html>
<head>
<title>您好套版</title>
</head>
<body>
<h1>{{ hello_str }}</h1>
</body>
</html>
urls.py修改
urlpatterns = [
path("hello/",hello),
]
接著瀏覽器輸入http://127.0.0.1:8000/hello
參考來源
Templates · Django Girls 學習指南
Python Django urls .py and views.py(5)
這次練習urls.py
urls.py可指定目前所有連結但需配合著views.py(可自取名字)來顯示
在website資料夾下建立一個views.py
在view.py中寫入function來回傳內容
http://127.0.0.1:8000/homexx/
更進階一點views.py加入
http://127.0.0.1:8000/yourinfo/陳00/35
urls.py可指定目前所有連結但需配合著views.py(可自取名字)來顯示
在website資料夾下建立一個views.py
在view.py中寫入function來回傳內容
from django.http import HttpResponse
def home(request):
return HttpResponse("yes this is your home success!")
接著修改urls.py內容
#原本
from django.contrib import admin
from django.urls import path
urlpatterns = [
path("admin/", admin.site.urls),
]
#修改後
from django.contrib import admin
from django.urls import path
from website.views import home #要import進來
urlpatterns = [
#path("admin/", admin.site.urls),
path("homexx/", home), #(網頁路徑,function)
]
接著瀏覽器輸入http://127.0.0.1:8000/homexx/
更進階一點views.py加入
def yourinfo(request,name, age):
return HttpResponse("您的名字{name},您的年齡{age}".format(name = name ,age = age))
修改urls.py
from website.views import home,yourinfo #要import進來
urlpatterns = [
path("homexx/", home),
path("yourinfo/<str:name>/<int:age>",yourinfo),
]
接著瀏覽器輸入http://127.0.0.1:8000/yourinfo/陳00/35
Python Django settings.py(4)
承上篇建置Django網站後會產生幾個檔
本篇大約簡單說明settings.py裡幾個比較常會使改到的
更進階後面會依文章需求補上
本篇大約簡單說明settings.py裡幾個比較常會使改到的
更進階後面會依文章需求補上
#這個開發時可True,正式發布時請一定要改False DEBUG = True
#預設語言為en-us #後期版本已經沒有zh-TW了請使用zh-hant(漢字繁體) or zh-hans(漢字簡體) LANGUAGE_CODE = 'zh-hant'多國語言可參考Using Language Identifiers (RFC 3066)
#系統時區預設UTC TIME_ZONE = 'Asia/Taipei'時區可參考List of tz database time zones
2021年11月17日 星期三
Python Django 建置專案(3)
終端機下輸入
http://127.0.0.1:8000/
django-admin.py startproject website產生如下圖目錄及檔案代表完成 本機啟動網站,終端機下輸入
cd website python manage.py runserver開啟瀏覽器查看是否成功
http://127.0.0.1:8000/
Python 安裝套件pip Django(2)
開啟VS Code 新增終端機
相關可安裝套件可參考pip的官網
#安裝pip(以後套件都可以使用pip安裝即可) python -m pip install -U pip #查看目前已安裝套件 pip list #安裝套件目前是3.2.9 pip install Django #移除套件 pip uninstall Django #安裝套件更新 python -m pip install -U Django
相關可安裝套件可參考pip的官網
Python 開發環境(1)
紀錄學習使用Python Django架站
作業系統Windows 10
開發軟體Python、Visual Studio Code基本上下一步安裝到底,只有Add Python To Path要打勾
Python初階語法學習推薦GrandmaCan -我阿嬤都會【python】4小時初學者Python教學有點底子看完應該就會
未來幾篇Django均以It’s Django - 用Python迅速打造Web應用這本書學習
作業系統Windows 10
開發軟體Python、Visual Studio Code基本上下一步安裝到底,只有Add Python To Path要打勾
Python初階語法學習推薦GrandmaCan -我阿嬤都會【python】4小時初學者Python教學有點底子看完應該就會
未來幾篇Django均以It’s Django - 用Python迅速打造Web應用這本書學習
2021年9月6日 星期一
.Net Core FluentValidation 一個Model多個驗證方式
.Net Core驗證方式FluentValidation通常都會用以下方式
新增一個Validator Class,撰寫驗證要輸入的欄位
DI注入Service
然後前端驗證
但是如果有另一個Service也是要用AAAViewModel但是驗證的欄位不一樣呢?
先新增一個Class如下
新增另一個Validator Class,撰寫驗證要輸入的欄位
DI注入另一個Service
然後前端驗證
參考來源
Two Validators for one Models
新增一個Validator Class,撰寫驗證要輸入的欄位
public XXXValidator()
{
RuleFor(x => x.xxxfiled).NotEmpty().WithMessage("請輸入欄位");
}
DI注入Service
services.AddTransient<IValidator<AAAViewModel>, XXXValidator>();
然後前端驗證
FluentValidation.Results.ValidationResult vResult = this._xxxValidator.Validate(model);
if (!vResult.IsValid)
{
throw new Exception(Function_ModelStateError.FormatToString(vResult));
}
但是如果有另一個Service也是要用AAAViewModel但是驗證的欄位不一樣呢?
先新增一個Class如下
//來源https://stackoverflow.com/questions/11607476/two-validators-for-one-model
public static class ValidationExtensions
{
public static FluentValidation.Results.ValidationResult ValidateModel<TModel, TValidator>(this TModel model, TValidator validator, ModelStateDictionary modelState)
where TModel : class
where TValidator : AbstractValidator<TModel>
{
var result = validator.Validate(model);
return result;
}
}
新增另一個Validator Class,撰寫驗證要輸入的欄位
public YYYValidator()
{
RuleFor(x => x.yyyfiled).NotEmpty().WithMessage("請輸入欄位");
}
DI注入另一個Service
services.AddTransient<IValidator<AAAViewModel>, YYYValidator>();
然後前端驗證
FluentValidation.Results.ValidationResult vResult = model.ValidateModel(new YYYValidator(), ModelState);//修改這
if (!vResult.IsValid)
{
throw new Exception(Function_ModelStateError.FormatToString(vResult));
}
參考來源
Two Validators for one Models
2021年8月6日 星期五
c# Linq Filter Detail(Labdba string array Like)
常常忘記這語法所以來記錄一下
情境個人資料內有許多經歷或是學歷
某天人資部需求想撈出那些人是碩士及博士
通常資料表會這樣開
員工資料主檔
情境個人資料內有許多經歷或是學歷
某天人資部需求想撈出那些人是碩士及博士
通常資料表會這樣開
員工資料主檔
public class Staff
{
public int StaffId { get; set; }
public string Name { get; set; }
public List EducationList { get; set; }//多種學歷
}
學歷檔
public class Education
{
public int EducationId { get; set; }
public int EducationType { get; set; }//假設有另一個資料表紀錄ID的意思 碩士是6 博士是7
public string SchoolName { get; set; }
}
抓取過濾碩士博士
int[] filter = new int[] { 6, 7 };
result = result.Where(x => x.EducationList.Any(y => filter.Contains(y.EducationType))).ToList();
string[] filter = searchTxt.Split(',' , ' ');
var result = data.Where(x => temp.Any(s => x.text.Contains(s) || x.content.Contains(s))).ToList();
備注用額外Detail符合的筆數
int mIsCondition = data.Sum(x => x.detail.Where(y => y.iscondition).Count());
2021年3月30日 星期二
.Net Core EF Core Power Tools
之前有篇文章有寫到.Net Core 問題4 DB First後來發現另一個VS套件可以使用
1.先至官網安裝EF Core Power Tools
2.在專案上右鍵EF Core Power Tools
3.點選Add Database Connection
4.填寫連線內容(跟Framework的模型很像吧)
5.選擇Table 或其他DB功能
6.Scaffold-DbContext
Context name:輸入您要的(預設都自動帶出)
Namespace:輸入您要的(預設都自動帶出)
EntityType path:您要存放的路徑資料夾, 例如你想放在專案下的Models資料夾裡就輸入Models
...中間略可不設定用預設比較好
Pluralize or signularize generated object names:將產生的物件名稱複數化或單數化",設定為"勾選"時 後面多出"s"
Use table and column names directly from the database:使用資料表原始名稱(CX_Name沒打勾時會變成CxName)跟之前的-use-database-names一樣
Use DataAnnotation attributes to configure the model:
Custiomize code using Handlebars templates
Include connection string in generated code:連線字串放於Context中建議不勾
Install the EF Core provider pageage in the project
最後覺得還是下指令的方便
參考來源
EF Core Power Tools
1.先至官網安裝EF Core Power Tools
2.在專案上右鍵EF Core Power Tools
3.點選Add Database Connection
4.填寫連線內容(跟Framework的模型很像吧)
5.選擇Table 或其他DB功能
6.Scaffold-DbContext
Context name:輸入您要的(預設都自動帶出)
Namespace:輸入您要的(預設都自動帶出)
EntityType path:您要存放的路徑資料夾, 例如你想放在專案下的Models資料夾裡就輸入Models
...中間略可不設定用預設比較好
Pluralize or signularize generated object names:將產生的物件名稱複數化或單數化",設定為"勾選"時 後面多出"s"
Use table and column names directly from the database:使用資料表原始名稱(CX_Name沒打勾時會變成CxName)跟之前的-use-database-names一樣
Use DataAnnotation attributes to configure the model:
Custiomize code using Handlebars templates
Include connection string in generated code:連線字串放於Context中建議不勾
Install the EF Core provider pageage in the project
最後覺得還是下指令的方便
參考來源
EF Core Power Tools
2021年2月3日 星期三
Bootstrap 問題 找不到popper.js
Bootstrap4.5.3使用了bootstrap-select 或是bootstrap-multiselect都會遇到下面問題
使用popper.js 1.16.1的話是可以的
參考來源
https://stackoverflow.com/questions/60837918/dropdown-js186-uncaught-typeerror-u-is-not-a-constructor-returning-when-i-clic
Bootstrap 4 error “Bootstrap dropdown require Popper.js”, with Aurelia CLI and Require.js
Uncaught TypeError: Bootstrap's dropdowns require Popper.js collapse.js:363 Uncaught TypeError: u is not a constructor缺少了Popper.js檔可至cdn下載所需的但目前版本v2.x以上好像也不行
使用popper.js 1.16.1的話是可以的
參考來源
https://stackoverflow.com/questions/60837918/dropdown-js186-uncaught-typeerror-u-is-not-a-constructor-returning-when-i-clic
Bootstrap 4 error “Bootstrap dropdown require Popper.js”, with Aurelia CLI and Require.js
2021年1月14日 星期四
.Net Core HTTP ERROR 413.1 - Request Entity Too Large
目前在寫一個.net core上傳
ok這都很簡單網路上一堆code
Html
User:我今天上傳了80MB的檔案出現了以下問題
好吧只好找解法了大概如下
1.Program加入
2.startup加入
3.Controller加入
看到一篇加入一個web.config程式碼如下
居然通了80MB上傳沒問題
一直以為.net core是沒web.conifg的
發現List<IFormFile> file是null但後端是有收到
感覺是大小沒問題只不過設定上有些不正確
接著就將startup那段註解的加了回去終於不null了
參考來源
.net core issues: 413 Request Entity Too Large nginx
Kestrel web server implementation in ASP.NET Core [资源分享].netcore 部署时遇到413 Request Entity Too Large 和 413Payload Too Large 的问题 asp.net core 3.0 解除文件上传大小限制,500.30、413、api-post-form方法拿不到参数 解决方案 How to increase file upload size in ASP.NET Core https://www.aspsnippets.com/Articles/ASPNet-Core-IFormFile-always-returns-NULL.aspx .Net Core IFormFile 始终为空的问题
ok這都很簡單網路上一堆code
Html
<form enctype="multipart/form-data" method="post" asp-controller="FileStream" asp-action="Upload">
多選檔案:<input type="file" name="File" multiple /> <input type="submit" value="上傳" />
</form>
Controller
private IWebHostEnvironment _hostingEnvironment;
private readonly IFunction_Error _functionerror;
public FileStreamController(IWebHostEnvironment environment, IFunction_Error functionerror)
{
_hostingEnvironment = environment;
}
public IActionResult Index()
{
return View();
}
[HttpPost]
public async Task<IActionResult> Upload(List<IFormFile> file)
{
string uploadfolder = Path.Combine(_hostingEnvironment.WebRootPath, "files");
foreach (IFormFile item in file)
{
if (item.Length > 0)
{
string filePath = Path.Combine(uploadfolder, item.FileName);
using (Stream fileStream = new FileStream(filePath, FileMode.Create))
{
await item.CopyToAsync(fileStream);
}
}
}
return View();
}
Ok很簡單吧User:我今天上傳了80MB的檔案出現了以下問題
好吧只好找解法了大概如下
serverOptions.Limits.MaxRequestBodySize = long.MaxValue; ...
services.Configure(options => { options.MultipartBodyLengthLimit = long.MaxValue; .... });
[DisableRequestSizeLimit]以上三種都沒用最後註解掉
看到一篇加入一個web.config程式碼如下
居然通了80MB上傳沒問題
一直以為.net core是沒web.conifg的
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="2147483647" />
</requestFiltering>
</security>
</system.webServer>
</configuration>
User說:剛剛上傳了150MB的檔案都沒出現錯誤但檔案又沒傳上去發現List<IFormFile> file是null但後端是有收到
感覺是大小沒問題只不過設定上有些不正確
接著就將startup那段註解的加了回去終於不null了
services.Configure注意上面的MaxValue要修正阿不要真的那麼大還是要依專案來設定(options => { options.BufferBodyLengthLimit = long.MaxValue; options.KeyLengthLimit = int.MaxValue; options.MultipartBodyLengthLimit = long.MaxValue; options.MultipartBoundaryLengthLimit = int.MaxValue; options.ValueCountLimit = int.MaxValue; options.ValueLengthLimit = int.MaxValue; });
參考來源
.net core issues: 413 Request Entity Too Large nginx
Kestrel web server implementation in ASP.NET Core [资源分享].netcore 部署时遇到413 Request Entity Too Large 和 413Payload Too Large 的问题 asp.net core 3.0 解除文件上传大小限制,500.30、413、api-post-form方法拿不到参数 解决方案 How to increase file upload size in ASP.NET Core https://www.aspsnippets.com/Articles/ASPNet-Core-IFormFile-always-returns-NULL.aspx .Net Core IFormFile 始终为空的问题
2020年12月25日 星期五
Docker Rename TAG(6)
先前學會建立Image後發現TAG都是latest
TAG可用來區別版本是相當好用的
先前Build時語法如下
他們的Image Id是一樣的
參考來源
docker image tag
Docker how to change repository name or rename image?
TAG可用來區別版本是相當好用的
先前Build時語法如下
docker build -t samplecore .可改成
docker build -t samplecore:1.0 .如果要修改iamge名稱和tag時可輸入
指令 Image ID REPOSITORY:TAG docker image tag 4c575b75980e officialcore:2.0這時刪除掉舊的1.0時會發現磁碟的容量大小沒變
他們的Image Id是一樣的
參考來源
docker image tag
Docker how to change repository name or rename image?
Docker 備份及還原Image(5)
建立了image後一定會想到到時如果換機器
或是要發佈到正式機器但又不想重新產生image
打開powershell
備份
docker save
docker load
或是要發佈到正式機器但又不想重新產生image
打開powershell
備份
先查看目前 docker images
指令 目的端 REPOSITORY:TAG docker save -o d:\temp\samplecore.tar samplecore:latest還原
指令 來源端 docker load -i d:\temp\samplecore.tar參考來源
docker save
docker load
2020年12月24日 星期四
Docker Asp.Net Core建立Image(4)
測試了半天Dockerfile的部分還是不太懂
依微軟的的範例好像也做不太出來(功力太淺)
網路上找到了[個人筆記] docker個人筆記進行測試後修改居然可以使用
來看一下我的目錄吧
一個方案四個專案將Dockerfile放一起
撰寫Dockerfile(這邊是重點寫錯就無法成功)
內容為何可參考如何將 ASP.NET Core 2.1 網站部署到 Docker 容器中
到專案料夾底下打開powershell執行
也可輸入以下
藍色:IN USE的
紅色:可刪除
紫色:可留著重複使用
參考來源
[個人筆記] docker個人筆記
如何將 ASP.NET Core 2.1 網站部署到 Docker 容器中
依微軟的的範例好像也做不太出來(功力太淺)
網路上找到了[個人筆記] docker個人筆記進行測試後修改居然可以使用
來看一下我的目錄吧
一個方案四個專案將Dockerfile放一起
撰寫Dockerfile(這邊是重點寫錯就無法成功)
內容為何可參考如何將 ASP.NET Core 2.1 網站部署到 Docker 容器中
FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build WORKDIR app # copy csproj and restore as distinct layers COPY *.sln . COPY coresample.language/*.csproj ./coresample.language/ COPY coresample.model/*.csproj ./coresample.model/ COPY coresample.service/*.csproj ./coresample.service/ COPY coresample.web/*.csproj ./coresample.web/ # copy everything else and build app COPY coresample.language/. ./coresample.language/ COPY coresample.model/. ./coresample.model/ COPY coresample.service/. ./coresample.service/ COPY coresample.web/. ./coresample.web/ RUN dotnet publish -c Release -o out FROM mcr.microsoft.com/dotnet/core/aspnet:3.1 AS runtime ENV ASPNETCORE_URLS=http://+:8080 WORKDIR /app EXPOSE 8080/tcp COPY --from=build /app . ENTRYPOINT ["dotnet", "coresample.web.dll"]2022-08-31補充vs2022在專案 > 右鍵 > 加入 > Docker支援也可跑出上述功能
到專案料夾底下打開powershell執行
docker build -t samplecore . 中間略... Successfully built da35a45ea2bf Successfully tagged samplecore:latest開啟軟體Docker Desktop
也可輸入以下
指令 名稱 port 來源image docker run -d --name=MyFistApp -p 8081:80 samplecore:latest輸入資料 > Run 在瀏覽器中顯示 剛剛的步驟產生了許多image
藍色:IN USE的
紅色:可刪除
紫色:可留著重複使用
參考來源
[個人筆記] docker個人筆記
如何將 ASP.NET Core 2.1 網站部署到 Docker 容器中
訂閱:
文章 (Atom)








































