From cd1d71ca885c22c3ad56640d5eaeaf066c8a9e7c Mon Sep 17 00:00:00 2001 From: Bobo Date: Sun, 20 Jun 2021 13:08:10 +0800 Subject: [PATCH] add docer-componse --- .../CoreCms.Net.Web.Admin.csproj | 5 +- CoreCms.Net.Web.Admin/Dockerfile | 11 ++++ CoreCms.Net.Web.Admin/Program.cs | 2 +- CoreCms.Net.Web.Admin/appsettings.json | 10 ++-- CoreCms.Net.Web.Admin/nlog.config | 2 +- .../CoreCms.Net.Web.WebApi.csproj | 5 +- CoreCms.Net.Web.WebApi/Dockerfile | 14 +++++ CoreCms.Net.Web.WebApi/Program.cs | 2 +- CoreCms.Net.Web.WebApi/appsettings.json | 10 ++-- CoreCms.Net.Web.WebApi/nlog.config | 2 +- Untitled-2.yml | 54 +++++++++++++++++++ docker-compose.yaml | 48 +++++++++++++++++ 12 files changed, 149 insertions(+), 16 deletions(-) create mode 100644 CoreCms.Net.Web.Admin/Dockerfile create mode 100644 CoreCms.Net.Web.WebApi/Dockerfile create mode 100644 Untitled-2.yml create mode 100644 docker-compose.yaml diff --git a/CoreCms.Net.Web.Admin/CoreCms.Net.Web.Admin.csproj b/CoreCms.Net.Web.Admin/CoreCms.Net.Web.Admin.csproj index 7241c19..66899f4 100644 --- a/CoreCms.Net.Web.Admin/CoreCms.Net.Web.Admin.csproj +++ b/CoreCms.Net.Web.Admin/CoreCms.Net.Web.Admin.csproj @@ -93,7 +93,7 @@ - + Always @@ -426,6 +426,9 @@ Always + + PreserveNewest + diff --git a/CoreCms.Net.Web.Admin/Dockerfile b/CoreCms.Net.Web.Admin/Dockerfile new file mode 100644 index 0000000..6e46781 --- /dev/null +++ b/CoreCms.Net.Web.Admin/Dockerfile @@ -0,0 +1,11 @@ +FROM mcr.microsoft.com/dotnet/aspnet:5.0 + +WORKDIR /app + +EXPOSE 80 + +COPY ./ /app + +ENV TZ=Asia/Shanghai + +ENTRYPOINT ["dotnet", "CoreCms.Net.Web.Admin.dll"] \ No newline at end of file diff --git a/CoreCms.Net.Web.Admin/Program.cs b/CoreCms.Net.Web.Admin/Program.cs index 0761820..818d960 100644 --- a/CoreCms.Net.Web.Admin/Program.cs +++ b/CoreCms.Net.Web.Admin/Program.cs @@ -25,7 +25,7 @@ namespace CoreCms.Net.Web.Admin try { //确保NLog.config中连接字符串与appsettings.json中同步 - NLogUtil.EnsureNlogConfig("nLog.config"); + NLogUtil.EnsureNlogConfig("NLog.config"); //throw new Exception("测试异常");//for test //其他项目启动时需要做的事情 NLogUtil.WriteAll(NLog.LogLevel.Trace, LogType.Web, "网站启动", "网站启动成功"); diff --git a/CoreCms.Net.Web.Admin/appsettings.json b/CoreCms.Net.Web.Admin/appsettings.json index 3b4bbb3..f717fda 100644 --- a/CoreCms.Net.Web.Admin/appsettings.json +++ b/CoreCms.Net.Web.Admin/appsettings.json @@ -1,11 +1,11 @@ 锘縶 "ConnectionStrings": { - "DbType": "SqlServer", //鏁版嵁搴撳皢鏀寔涓ょ妯″紡銆怱qlServer,MySql銆 - "SqlConnection": "Server=127.0.0.1;uid=coreshop;pwd=coreshop;Database=coreshop;MultipleActiveResultSets=true;" + "DbType": "MySql", //鏁版嵁搴撳皢鏀寔涓ょ妯″紡銆怱qlServer,MySql銆 + //"SqlConnection": "Server=127.0.0.1;uid=coreshop;pwd=coreshop;Database=coreshop;MultipleActiveResultSets=true;" //SqlServer鏁版嵁搴撹繛鎺ュ瓧绗︿覆锛岄渶瑕佸紑鍚暟鎹簱杩炴帴澶嶇敤銆怣ultipleActiveResultSets=true銆 - //"SqlConnection": "Server=127.0.0.1;Port=3306;Database=coreshopMysql;Uid=coreshopMysql;Pwd=coreshopMysql;CharSet=utf8;pooling=true;SslMode=None;Allow User Variables=true" - //Mysql鏁版嵁搴撻摼鎺ュ瓧绗︿覆锛岃淇濇寔鍚庨潰鐨勫睘鎬у埆灏戙傜粡杩囨祴璇曪紝mysql鐗堟湰闇瑕5.7鎴栦互涓 + "SqlConnection": "Server=192.168.20.62;Port=3306;Database=coreshop;Uid=root;Pwd=admin" + // Mysql鏁版嵁搴撻摼鎺ュ瓧绗︿覆锛岃淇濇寔鍚庨潰鐨勫睘鎬у埆灏戙傜粡杩囨祴璇曪紝mysql鐗堟湰闇瑕5.7鎴栦互涓 }, //瀹氭椂浠诲姟绠$悊闈㈡澘鐨勮处鎴峰瘑鐮 "HangFire": { @@ -20,7 +20,7 @@ "RedisConfig": { "Enabled": false, //鍚敤redis浣滀负鍐呭瓨閫夋嫨 "UseRedisMessageQueue": false, //鍚敤redis浣滀负闃熷垪閫夋嫨 - "ConnectionString": "redis.demo.coreshop.com.cn:6379,password=coreshop,connectTimeout=1000,connectRetry=1,syncTimeout=10000,DefaultDatabase=8" //redis鏁版嵁搴撹繛鎺ュ瓧绗︿覆 + "ConnectionString": "192.168.20.62:6379,password=123456,connectTimeout=1000,connectRetry=1,syncTimeout=10000,DefaultDatabase=8" //redis鏁版嵁搴撹繛鎺ュ瓧绗︿覆 }, //jwt鎺堟潈璁よ瘉鐨勪竴浜涜缃 "JwtConfig": { diff --git a/CoreCms.Net.Web.Admin/nlog.config b/CoreCms.Net.Web.Admin/nlog.config index 1a0fc38..b96d8ec 100644 --- a/CoreCms.Net.Web.Admin/nlog.config +++ b/CoreCms.Net.Web.Admin/nlog.config @@ -14,7 +14,7 @@ dbProvider="Microsoft.Data.SqlClient.SqlConnection, Microsoft.Data.SqlClient" connectionString="Server=127.0.0.1;Database=BaseMIS;User ID=sa;Password=123456" --> - + INSERT INTO SysNLogRecords (LogDate,LogLevel,LogType,LogTitle,Logger,Message,MachineName,MachineIp,NetRequestMethod diff --git a/CoreCms.Net.Web.WebApi/CoreCms.Net.Web.WebApi.csproj b/CoreCms.Net.Web.WebApi/CoreCms.Net.Web.WebApi.csproj index 738e2cb..eaef5b2 100644 --- a/CoreCms.Net.Web.WebApi/CoreCms.Net.Web.WebApi.csproj +++ b/CoreCms.Net.Web.WebApi/CoreCms.Net.Web.WebApi.csproj @@ -87,7 +87,7 @@ - + Always @@ -120,6 +120,9 @@ Always + + PreserveNewest + diff --git a/CoreCms.Net.Web.WebApi/Dockerfile b/CoreCms.Net.Web.WebApi/Dockerfile new file mode 100644 index 0000000..f8bafdc --- /dev/null +++ b/CoreCms.Net.Web.WebApi/Dockerfile @@ -0,0 +1,14 @@ +FROM mcr.microsoft.com/dotnet/aspnet:5.0 + +WORKDIR /app + +EXPOSE 80 + +COPY ./ /app + +ENV TZ=Asia/Shanghai + +RUN sed -i 's/MinProtocol = TLSv1.2/MinProtocol = TLSv1/g' /etc/ssl/openssl.cnf +RUN sed -i 's/MinProtocol = TLSv1.2/MinProtocol = TLSv1/g' /usr/lib/ssl/openssl.cnf + +ENTRYPOINT ["dotnet", "CoreCms.Net.Web.WebApi.dll"] \ No newline at end of file diff --git a/CoreCms.Net.Web.WebApi/Program.cs b/CoreCms.Net.Web.WebApi/Program.cs index 1c18470..bdeb09b 100644 --- a/CoreCms.Net.Web.WebApi/Program.cs +++ b/CoreCms.Net.Web.WebApi/Program.cs @@ -26,7 +26,7 @@ namespace CoreCms.Net.Web.WebApi try { //确保NLog.config中连接字符串与appsettings.json中同步 - NLogUtil.EnsureNlogConfig("nLog.config"); + NLogUtil.EnsureNlogConfig("NLog.config"); //其他项目启动时需要做的事情 NLogUtil.WriteAll(LogLevel.Trace, LogType.Web, "接口启动", "接口启动成功"); diff --git a/CoreCms.Net.Web.WebApi/appsettings.json b/CoreCms.Net.Web.WebApi/appsettings.json index 3b4bbb3..f717fda 100644 --- a/CoreCms.Net.Web.WebApi/appsettings.json +++ b/CoreCms.Net.Web.WebApi/appsettings.json @@ -1,11 +1,11 @@ 锘縶 "ConnectionStrings": { - "DbType": "SqlServer", //鏁版嵁搴撳皢鏀寔涓ょ妯″紡銆怱qlServer,MySql銆 - "SqlConnection": "Server=127.0.0.1;uid=coreshop;pwd=coreshop;Database=coreshop;MultipleActiveResultSets=true;" + "DbType": "MySql", //鏁版嵁搴撳皢鏀寔涓ょ妯″紡銆怱qlServer,MySql銆 + //"SqlConnection": "Server=127.0.0.1;uid=coreshop;pwd=coreshop;Database=coreshop;MultipleActiveResultSets=true;" //SqlServer鏁版嵁搴撹繛鎺ュ瓧绗︿覆锛岄渶瑕佸紑鍚暟鎹簱杩炴帴澶嶇敤銆怣ultipleActiveResultSets=true銆 - //"SqlConnection": "Server=127.0.0.1;Port=3306;Database=coreshopMysql;Uid=coreshopMysql;Pwd=coreshopMysql;CharSet=utf8;pooling=true;SslMode=None;Allow User Variables=true" - //Mysql鏁版嵁搴撻摼鎺ュ瓧绗︿覆锛岃淇濇寔鍚庨潰鐨勫睘鎬у埆灏戙傜粡杩囨祴璇曪紝mysql鐗堟湰闇瑕5.7鎴栦互涓 + "SqlConnection": "Server=192.168.20.62;Port=3306;Database=coreshop;Uid=root;Pwd=admin" + // Mysql鏁版嵁搴撻摼鎺ュ瓧绗︿覆锛岃淇濇寔鍚庨潰鐨勫睘鎬у埆灏戙傜粡杩囨祴璇曪紝mysql鐗堟湰闇瑕5.7鎴栦互涓 }, //瀹氭椂浠诲姟绠$悊闈㈡澘鐨勮处鎴峰瘑鐮 "HangFire": { @@ -20,7 +20,7 @@ "RedisConfig": { "Enabled": false, //鍚敤redis浣滀负鍐呭瓨閫夋嫨 "UseRedisMessageQueue": false, //鍚敤redis浣滀负闃熷垪閫夋嫨 - "ConnectionString": "redis.demo.coreshop.com.cn:6379,password=coreshop,connectTimeout=1000,connectRetry=1,syncTimeout=10000,DefaultDatabase=8" //redis鏁版嵁搴撹繛鎺ュ瓧绗︿覆 + "ConnectionString": "192.168.20.62:6379,password=123456,connectTimeout=1000,connectRetry=1,syncTimeout=10000,DefaultDatabase=8" //redis鏁版嵁搴撹繛鎺ュ瓧绗︿覆 }, //jwt鎺堟潈璁よ瘉鐨勪竴浜涜缃 "JwtConfig": { diff --git a/CoreCms.Net.Web.WebApi/nlog.config b/CoreCms.Net.Web.WebApi/nlog.config index 1a0fc38..b96d8ec 100644 --- a/CoreCms.Net.Web.WebApi/nlog.config +++ b/CoreCms.Net.Web.WebApi/nlog.config @@ -14,7 +14,7 @@ dbProvider="Microsoft.Data.SqlClient.SqlConnection, Microsoft.Data.SqlClient" connectionString="Server=127.0.0.1;Database=BaseMIS;User ID=sa;Password=123456" --> - + INSERT INTO SysNLogRecords (LogDate,LogLevel,LogType,LogTitle,Logger,Message,MachineName,MachineIp,NetRequestMethod diff --git a/Untitled-2.yml b/Untitled-2.yml new file mode 100644 index 0000000..5a05a57 --- /dev/null +++ b/Untitled-2.yml @@ -0,0 +1,54 @@ +version: '3' +services: + frontservice: + container_name: front-backend + build: + context: ./front/publish + dockerfile: Dockerfile + depends_on: + - redis + - mysql + ports: + - 8088:80 + labels: + description: 'front backend web' + restart: always + + webapiservice: + container_name: web-api + build: + context: ./api/publish + dockerfile: Dockerfile + depends_on: + - redis + - mysql + ports: + - 8089:80 + labels: + description: 'web api' + restart: always + + redis: + image: redis:lastest + ports: + - 6379:6379 + expose: + - 6379 + volumes: + command: + redis-server + + mysql: + image: mysql:5.7.19 + restart: always + ports: + - 3306:3306 + expose: + - 3306 + volumes: + - /usr/local/mysql/data:/var/lib/mysql + - /usr/local/mysql/conf.d:/etc/mysql/conf.d + command: mysqld --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci --lower_case_table_names=2 + environment: + - MYSQL_ROOT_PASSWORD=admin + \ No newline at end of file diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000..864364c --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,48 @@ +version: '3' +services: + frontservice: + container_name: front-backend + build: + context: ./front/publish + dockerfile: Dockerfile + ports: + - 8088:80 + labels: + description: 'front backend web' + restart: always + + webapiservice: + container_name: web-api + build: + context: ./api/publish + dockerfile: Dockerfile + ports: + - 8089:80 + labels: + description: 'web api' + restart: always + +# redis: +# image: redis:lastest +# ports: +# - 6379:6379 +# expose: +# - 6379 +# volumes: +# command: +# redis-server + +# mysql: +# image: mysql:5.7.19 +# restart: always +# ports: +# - 3306:3306 +# expose: +# - 3306 +# volumes: +# - /usr/local/mysql/data:/var/lib/mysql +# - /usr/local/mysql/conf.d:/etc/mysql/conf.d +# command: mysqld --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci --lower_case_table_names=2 +# environment: +# - MYSQL_ROOT_PASSWORD=admin + \ No newline at end of file