--- tags: AAT disqus: hackmd --- # Docker 1. 將整個DataValueChain方案拉到自己的image build環境 2. 開啟DvcApiService內的LaunchSettings.json,修改Docker 部分的DVC_DB_CONNSTR與DVC_ES_SERVERS 3. 點選右下角docker鯨魚右鍵,switch to Linux containers 4. 點選Dockerfile右鍵,Build Docker Image 5. 開啟Windows PowerShell > docker images --確認image已build完成 (dvcapiservice:latest) > docker save --output dvcapiservice.tar dvcapiservice:latest --將image包成.tar檔案並存進資料夾 6.開啟WinSCP,連接到要部屬的環境,將dvcapiservice.tar上傳到root的位置 (如果build image的環境連不到要部屬的環境,可把dvcapiservice.tar檔案拉回自己的本地端,再在本地端使用WinSCP上傳檔案) 7.開啟Solar-PuTTY,連接到要部屬的環境 > login as: root > password: 53189636 8.如果是新環境,要先建置docker環境 1. 更新 yum > yum update -y 2. 安裝 Docker CE https://docs.docker.com/install/linux/docker-ce/centos/ > sudo yum install -y yum-utils > sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo 2.1 Install from RPM package > yum install wget (如果沒有wget 要先安裝) > wget https://download.docker.com/linux/centos/7/x86_64/stable/Packages/containerd.io-1.2.6-3.3.el7.x86_64.rpm --下載檔案 > wget https://download.docker.com/linux/centos/7/x86_64/stable/Packages/docker-ce-19.03.6-3.el7.x86_64.rpm --下載檔案 > yum install containerd.io-1.2.6-3.3.el7.x86_64.rpm --安裝檔案 > yum install docker-ce-19.03.6-3.el7.x86_64.rpm --安裝檔案 3. CentOS 注意事項 #. 開機後自動啟動服務 https://docs.docker.com/install/linux/linux-postinstall//#configure-docker-to-start-on-boot > systemctl daemon-reload > systemctl enable docker.service > systemctl start docker.service 9.如果是新環境,要準備ASPNET CORE環境 安裝.NET CORE SDK https://dotnet.microsoft.com/download/dotnet-core/thank-you/sdk-3.1.100-windows-x64-installer (CentOs) → https://docs.microsoft.com/en-us/dotnet/core/install/linux-package-manager-rhel8 > yum install dotnet 透過docker拉回適當版本的 aspnet core > docker pull mcr.microsoft.com/dotnet/core/aspnet 如果有指定版本的話: (看自己build image時是用什麼版本): > docker pull mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim 1.4 透過docker拉回適當版本的 dotnet core sdk image > docker pull mcr.microsoft.com/dotnet/core/sdk 如果有指定版本的話(看自己build image時是用什麼版本): > docker pull mcr.microsoft.com/dotnet/core/sdk:3.1-buster 10.設定使用自我簽屬憑證 步驟一:先清空自我憑證(也就是刪除本地端已經信任的憑證)d > dotnet dev-certs https --clean 步驟二:重新建立本地端憑證 > dotnet dev-certs https -ep C:\https\aspnetapp.pfx -p 53189636 <--密碼 // 由於簽章會建立於本機,就暫時先以 c:\https 為存放憑證的目錄(dotnet工具會自動建立)。 > dotnet dev-certs https -ep ~/https/aspnetapp.pfx -p 53189636 // 隨後在建立容器時,需透過 -v 重新 mount 憑證路徑, // 屆時就讓容器內的c:\https指回本機的c:\https 步驟三:信任本地端憑證 (Windows Only) > dotnet dev-certs https --trust 11. > docker load --input dvcapiservice.tar --載入.tar內的image *** 請先確認CentOS 時區是否正確 > timedatectl 如果TZ不是Asia/Taipei,需先執行以下指令 > sudo timedatectl set-timezone Asia/Taipei 12. ↓ DVC_DB_CONNSTR 跟 DVC_ES_SERVERS 跟 DIEM_MQ_SERVER 要記得改 > docker run -t -d --restart always -p 8000:80 -p 8001:443 -e DVC_DB_CONNSTR="data source=172.xx.xx.xx;initial catalog=DVCDB;user id=sa;persist security info=True;password=Aat@53189636 size=4096;" -e DVC_ES_SERVERS="http://172.xx.xx.xx:9200;http://172.xx.xx.xx:9200;http://172.xx.xx.xx:9200;http://172.xx.xx.xx:9200" -e ASPNETCORE_URLS="https://+;http://+" -e ASPNETCORE_HTTPS_PORT=443 -e ASPNETCORE_Kestrel__Certificates__Default__Password="53189636" -e ASPNETCORE_Kestrel__Certificates__Default__Path=/https/aspnetapp.pfx -e ENABLE_DIEM=true -e DIEM_MQ_SERVER=172.xx.xx.xx -e TZ=Asia/Taipei -v ${HOME}/https:/https dvcapiservice:latest docker run -t -d --restart always -p 8000:80 -p 8001:443 -e DVC_DB_CONNSTR="data source=172.xx.xx.xx;initial catalog=DVCDB;user id=sa;persist security info=True;password=Aat@53189636;packet size=4096;" -e DVC_ES_SERVERS="http://172.xx.xx.xx:9200;http://172.xx.xx.xx:9200;http://172.xx.xx.xx:9200" -e ASPNETCORE_URLS="https://+;http://+" -e ASPNETCORE_HTTPS_PORT=443 -e ASPNETCORE_Kestrel__Certificates__Default__Password="53189636" -e ASPNETCORE_Kestrel__Certificates__Default__Path=/https/aspnetapp.pfx -e ENABLE_DIEM=true -e DIEM_MQ_SERVER=172.xx.xx.xx -e TZ=Asia/Taipei -v ${HOME}/https:/https dvcapiservice:latest 12. 回到本地端,開啟 https://172.xx.xx.xx:8001/api/ping (要修改docke部屬的路徑) ,測試是否建置成功 ----------------- # 停止所有的 containers $ docker stop $(docker ps -a -q) # 刪除所有的 containers $ docker rm $(docker ps -a -q) # 刪除所有的 images $ docker rmi $(docker images -a -q) 錯誤紀錄: 1. Build image 要用以下,才連得到SQL SERVER; FROM mcr.microsoft.com/dotnet/core/aspnet:3.0 AS base FROM mcr.microsoft.com/dotnet/core/sdk:3.0 AS build 或 FROM mcr.microsoft.com/dotnet/core/aspnet:3.1 AS base FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build 而要部屬docker的環境,目前觀察用 3.0-bionic & 3.1-buster & 3.1- buster-slim都可以 2. 好像部屬正確,但還是連不上SQL,可嘗試: 1.systemctl stop firewalld 2.重建憑證 3.systemctl stop docker & systemctl start docker ## RabbitMq部屬方法: 1.好像要pull :management的 才會有15672的管理介面 > docker run -d --restart always --hostname dvc --name rabbitmq -p 5672:5672 -p 15672:15672 -e TZ=Asia/Taipei -e RABBITMQ_DEFAULT_VHOST=dvc rabbitmq:3.8.5-management 2.用瀏覽器連到:15672 的管理介面,用 guest/guest登入,到 admin,新增一組帳號密碼 dvc / xxxxxxxx -e RABBITMQ_DEFAULT_USER=dvc -e RABBITMQ_DEFAULT_PASS=xxxxxxxx 2020/8/10: rabbitmq的時區沒辦法讀到 Asia/Taipei 時區,但目前沒有影響,就先不研究了 ## SQL Server部屬方法: 1.> docker volume create sqlserver (sqlserver 是volume名稱,下面的指令要指定到這個volume) 2.> docker run -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=xxxxxx@xxxxxx' -e TZ=Asia/Taipei -p 1400:1400 -e MSSQL_AGENT_ENABLED=True --name sqlserver -v sqlserver:/var/opt/mssql -d mcr.microsoft.com/mssql/server:2019-latest ## Inspector 部屬方法: 1.修改DvcToolkitCore的RabbitMqToolkit的factory.HostName 2.修改DIEM的RequestHelper的RESTclient的string[] DVC_API_SERVERS > docker run -e TZ=Asia/Taipei --restart always -d diemparcelman:latest ## some general 1. clean all unuseless container ```shell= docker rm $(docker ps --filter status=exited -q) ``` 2. get all container status(exites service) ```shell= sudo docker ps -d ``` 3. sql server on unutu ```shell= https://docs.microsoft.com/zh-tw/sql/linux/quickstart-install-connect-ubuntu?view=sql-server-linux-ver15&preserve-view=true ``` ## look for all docker container ```bash= docker container ls -a ``` ## turn tar to docker images ```bash= docker load -i mytomcat.tar ```