質問編集履歴

3

変更点(appsettings.jsonの接続文字列の変更(Windows認証→Sql Server認証)、作成したSql Server Linuxコンテナの情報の追加)

2021/09/06 14:15

投稿

ruchaos1192
ruchaos1192

スコア1

test CHANGED
File without changes
test CHANGED
@@ -42,7 +42,7 @@
42
42
 
43
43
  "ConnectionStrings": {
44
44
 
45
- "DefaultConnection": "Data Source=MySqlServer\SQLEXPRESS;Initial Catalog=NewDB1;Integrated Security=True;"
45
+ "DefaultConnection": "Data Source=localhost;Initial Catalog=ContosoUniversity1;User ID=SA;Password=<YourStrong!Passw0rd>"
46
46
 
47
47
  },
48
48
 
@@ -217,3 +217,37 @@
217
217
  }
218
218
 
219
219
  ```
220
+
221
+ ```ここに言語を入力
222
+
223
+ 作成した Sql server Linux コンテナ
224
+
225
+
226
+
227
+ Power Shell上で実施
228
+
229
+
230
+
231
+ docker pull mcr.microsoft.com/mssql/rhel/server:2019-CU1-rhel-8
232
+
233
+ docker run -e "ACCEPT_EULA=Y" -e "MSSQL_SA_PASSWORD=<YourStrong!Passw0rd>" -p 1433:1433 -d mcr.microsoft.com/mssql/rhel/server:2019-CU1-rhel-8
234
+
235
+ ```
236
+
237
+ ```
238
+
239
+ 現在稼働しているdockerコンテナ
240
+
241
+
242
+
243
+ PS C:\Users\mycomputer> docker container ls
244
+
245
+ CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
246
+
247
+ 77eccb6eab1b contosouniversity:dev "tail -f /dev/null" 12 minutes ago Up 12 minutes 0.0.0.0:51803->80/tcp, :::51803->80/tcp, 0.0.0.0:44360->443/tcp, :::44360->443/tcp SampleAPI001
248
+
249
+ 853e85ecd04a mcr.microsoft.com/mssql/rhel/server:2019-CU1-rhel-8 "/opt/mssql/bin/perm…" 2 days ago Up 22 minutes 0.0.0.0:1433->1433/tcp, :::1433->1433/tcp practical_swirles
250
+
251
+
252
+
253
+ ```

2

launchSettings.jsonの一部を改訂

2021/09/06 14:15

投稿

ruchaos1192
ruchaos1192

スコア1

test CHANGED
File without changes
test CHANGED
@@ -128,7 +128,7 @@
128
128
 
129
129
  ```ここに言語を入力
130
130
 
131
- launchSettings.json(API内のプロパティ)
131
+ launchSettings.json
132
132
 
133
133
 
134
134
 
@@ -150,60 +150,70 @@
150
150
 
151
151
  },
152
152
 
153
- "profiles": {
154
-
155
- "IIS Express": {
156
-
157
- "commandName": "IISExpress",
158
-
159
- "launchBrowser": true,
160
-
161
- "environmentVariables": {
162
-
163
- "ASPNETCORE_ENVIRONMENT": "Development",
164
-
165
- "ASPNETCORE_HOSTINGSTARTUPASSEMBLIES": "Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation"
166
-
167
- }
168
-
169
- },
170
-
171
- "ContosoUniversity": {
172
-
173
- "commandName": "Project",
174
-
175
- "launchBrowser": true,
176
-
177
- "environmentVariables": {
178
-
179
- "ASPNETCORE_ENVIRONMENT": "Development",
180
-
181
- "ASPNETCORE_HOSTINGSTARTUPASSEMBLIES": "Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation"
182
-
183
- },
184
-
185
- "dotnetRunMessages": "true",
186
-
187
- "applicationUrl": "https://localhost:5001;http://localhost:5000"
188
-
189
- },
190
-
191
- "Docker": {
192
-
193
- "commandName": "Docker",
194
-
195
- "launchBrowser": true,
196
-
197
- "launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}",
198
-
199
- "publishAllPorts": true,
200
-
201
- "useSSL": true
153
+ "profiles": {
154
+
155
+ "IIS Express": {
156
+
157
+ "commandName": "IISExpress",
158
+
159
+ "launchBrowser": true,
160
+
161
+ "environmentVariables": {
162
+
163
+ "ASPNETCORE_ENVIRONMENT": "Development",
164
+
165
+ "ASPNETCORE_HOSTINGSTARTUPASSEMBLIES": "Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation"
166
+
167
+ }
168
+
169
+ },
170
+
171
+ "ContosoUniversity": {
172
+
173
+ "commandName": "Project",
174
+
175
+ "launchBrowser": true,
176
+
177
+ "environmentVariables": {
178
+
179
+ "ASPNETCORE_ENVIRONMENT": "Development",
180
+
181
+ "ASPNETCORE_HOSTINGSTARTUPASSEMBLIES": "Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation"
182
+
183
+ },
184
+
185
+ "dotnetRunMessages": "true",
186
+
187
+ "applicationUrl": "https://localhost:5001;http://localhost:5000"
188
+
189
+ },
190
+
191
+ "Docker": {
192
+
193
+ "commandName": "Docker",
194
+
195
+ "launchBrowser": true,
196
+
197
+ "launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}",
198
+
199
+ "environmentVariables": {
200
+
201
+ "ASPNETCORE_URLS": "https://+:443;http://+:80",
202
+
203
+ "ASPNETCORE_HTTPS_PORT": "44360"
204
+
205
+ },
206
+
207
+ "httpPort": 51803,
208
+
209
+ "useSSL": true,
210
+
211
+ "sslPort": 44360
212
+
213
+ }
202
214
 
203
215
  }
204
216
 
205
- }
206
-
207
217
  }
208
218
 
209
219
  ```

1

APIの構成情報の追加(appsettings.json、launchSettings.json、Dockerfile)

2021/09/06 02:39

投稿

ruchaos1192
ruchaos1192

スコア1

test CHANGED
File without changes
test CHANGED
@@ -25,3 +25,185 @@
25
25
  ASP.net core API側のappsettings.jsonの接続文字列について変更して接続、
26
26
 
27
27
  もしくはAPI側のDocker file内で接続文字列を追加するのかご教授いただければと思います。
28
+
29
+
30
+
31
+ (追記)ASP.net Coreで作成したAPIはDockerを挟まず、既存のSql ServerのローカルDB環境には
32
+
33
+ IIS上から接続できております。また、接続文字列はAPI内のappsettings.json内のDefaultConnection
34
+
35
+ を用いて接続しております。以下APIのappsettings.jsonのコードのになります。
36
+
37
+
38
+
39
+ ```ここに言語を入力
40
+
41
+ {
42
+
43
+ "ConnectionStrings": {
44
+
45
+ "DefaultConnection": "Data Source=MySqlServer\SQLEXPRESS;Initial Catalog=NewDB1;Integrated Security=True;"
46
+
47
+ },
48
+
49
+ "Logging": {
50
+
51
+ "LogLevel": {
52
+
53
+ "Default": "Information",
54
+
55
+ "Microsoft": "Warning",
56
+
57
+ "Microsoft.Hosting.Lifetime": "Information",
58
+
59
+ "Microsoft.EntityFrameworkCore.Database.Command": "Information"
60
+
61
+ }
62
+
63
+ },
64
+
65
+ "AllowedHosts": "*"
66
+
67
+ }
68
+
69
+ ```
70
+
71
+ また、VisualのDocker自動生成にてDockerfileの生成を行いましたのでDockerfileとAPI全体のプロパティを
72
+
73
+ 載せておきます。
74
+
75
+ ```ここに言語を入力
76
+
77
+ Dockerfile
78
+
79
+
80
+
81
+ #See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.
82
+
83
+
84
+
85
+ FROM mcr.microsoft.com/dotnet/aspnet:5.0 AS base
86
+
87
+ WORKDIR /app
88
+
89
+ EXPOSE 80
90
+
91
+ EXPOSE 443
92
+
93
+
94
+
95
+ FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build
96
+
97
+ WORKDIR /src
98
+
99
+ COPY ["SampleAPI001/SampleAPI001.csproj", "SampleAPI001/"]
100
+
101
+ RUN dotnet restore "SampleAPI001/SampleAPI001.csproj"
102
+
103
+ COPY . .
104
+
105
+ WORKDIR "/src/SampleAPI001"
106
+
107
+ RUN dotnet build "SampleAPI001.csproj" -c Release -o /app/build
108
+
109
+
110
+
111
+ FROM build AS publish
112
+
113
+ RUN dotnet publish "SampleAPI001.csproj" -c Release -o /app/publish
114
+
115
+
116
+
117
+ FROM base AS final
118
+
119
+ WORKDIR /app
120
+
121
+ COPY --from=publish /app/publish .
122
+
123
+ ENTRYPOINT ["dotnet", "SampleAPI001.dll"]
124
+
125
+
126
+
127
+ ```
128
+
129
+ ```ここに言語を入力
130
+
131
+ launchSettings.json(API内のプロパティ)
132
+
133
+
134
+
135
+ {
136
+
137
+ "iisSettings": {
138
+
139
+ "windowsAuthentication": false,
140
+
141
+ "anonymousAuthentication": true,
142
+
143
+ "iisExpress": {
144
+
145
+ "applicationUrl": "http://localhost:24399",
146
+
147
+ "sslPort": 44335
148
+
149
+ }
150
+
151
+ },
152
+
153
+ "profiles": {
154
+
155
+ "IIS Express": {
156
+
157
+ "commandName": "IISExpress",
158
+
159
+ "launchBrowser": true,
160
+
161
+ "environmentVariables": {
162
+
163
+ "ASPNETCORE_ENVIRONMENT": "Development",
164
+
165
+ "ASPNETCORE_HOSTINGSTARTUPASSEMBLIES": "Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation"
166
+
167
+ }
168
+
169
+ },
170
+
171
+ "ContosoUniversity": {
172
+
173
+ "commandName": "Project",
174
+
175
+ "launchBrowser": true,
176
+
177
+ "environmentVariables": {
178
+
179
+ "ASPNETCORE_ENVIRONMENT": "Development",
180
+
181
+ "ASPNETCORE_HOSTINGSTARTUPASSEMBLIES": "Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation"
182
+
183
+ },
184
+
185
+ "dotnetRunMessages": "true",
186
+
187
+ "applicationUrl": "https://localhost:5001;http://localhost:5000"
188
+
189
+ },
190
+
191
+ "Docker": {
192
+
193
+ "commandName": "Docker",
194
+
195
+ "launchBrowser": true,
196
+
197
+ "launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}",
198
+
199
+ "publishAllPorts": true,
200
+
201
+ "useSSL": true
202
+
203
+ }
204
+
205
+ }
206
+
207
+ }
208
+
209
+ ```