LoginSignup
0
0

More than 3 years have passed since last update.

初めてのASP.NET core チュートリアルのエラー「docker」や「curl: (3)エラー」などを解決した話

Last updated at Posted at 2019-04-25

こんにちは。
今、.NET coreのチュートリアルに挑戦しているのですが、
書いている通りにやっても怒られまくっています💦

私のエラー解決方法をほんの少しですがメモしておきます(^▽^)

docker.gif

1、チュートリアル

▼dockerでASP.NET coreをMySQLに接続する
ASP.NET core and MySQL with Docker

🔰な私には、んんん?な状況なのですが、
読んでいるC#の参考書に
「英語の単語を羅列して質問するより本に書いている例文を使う方が近道(というか伝わるよね)」
ということが書かれていました。

わからない事を棚卸するとキリがないので、ズンズン進めています:relaxed:

2、つまずいたところ!

error.gif

①ポートを変更する

  • チュートリアルには下記のようになっているので、このままターミナルでコマンドをたたいてみた!
# Add a new department
> curl -X POST \
  http://localhost:5000/api/Department/ \
  -H 'cache-control: no-cache' \
  -H 'content-type: application/json' \
  -H 'postman-token: ce786dd0-5d17-bc94-81d3-8191203649cb' \
  -d '{
 "Name": "CSE"
}'
  • エラーになりました。(うまくいかない:frowning2:
curl -X POST
Invoke-WebRequest : パラメーター名 'X' に一致するパラメーターが見つかりません。
発生場所 行:1 文字:6
+ curl -X POST \
+      ~~
    + CategoryInfo          : InvalidArgument: (:) [Invoke-WebRequest]、ParameterBindingException
    + FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
  • ググってみたところ、下記のコマンドを使ってエイリアスの確認ができるとか!
 gal curl
  • curlになっていない!「Invoke-WebRequest」って誰?
CommandType     Name                                               Version    Source
-----------     ----                                               -------    ------
Alias           curl -> Invoke-WebRequest

★参考にした記事

こちらの記事を参考にしました(ありがとうございます♡)
https://devadjust.exblog.jp/22690878/

「.exe」付きで curl を実行すれば期待どおりの動作となる。
とあったので、やってみました。

 curl.exe http://localhost:5000/api/Department/

成功(/・ω・)/

②DB登録がうまくいかない!

チュートリアルの通りやってみると

  -d '{
 "Name": "John Doe",
 "DepartmentID": 1,
 "Email": "johndoe@doejohn.com",
 "PhoneNumber": "1122334455"
}'

エラーになる:thinking:

curl: (3) Port number ended with ','
curl: (3) [globbing] unmatched close brace/bracket in column 52

空白文字列があるとダメなのかも?

'cache-control: no-cache' -H 'content-type: application/json'-H 'postman-token: ce786dd0-5d17-bc94-81d3-8191203649cb'

成功(/・ω・)/

③コンフリクトが起きた!

Conflict. The container name "/webapp.test" is already in use by container "1cf53746a4f3e592f93bd207705f3ae04cf49e26150c027b200fdfd0c057e43d". You have to remove (or rename) that container to be able to reuse that name.
  • リムーブしろって怒られているようなので、コンテナを削除してみることにしました。
  • コンテナが動いていたら削除できない!って怒られるのでstopしてあげる
docker stop CONTAINER名
  • Stopしたので削除します!
docker rm CONTAINER名
  • きちんと削除できたら再度buildからやり直してrunしてみたら成功(/・ω・)/
Successfully built ビルドのID
Successfully tagged webapp:Debug

④runしたらこんなエラーが出た!

③の段階でrunしたらエラーが出ました(一難去ってまた一難)
もう終わる気がしない:money_mouth:

docker: Error response from daemon: Get https://registry-1.docker.io/v2/: net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers).

なんだろうこれ。と思って「 https://registry-1.docker.io/v2/ 」をたたいてみたら
こんな画面になりました(益々わからないよ!)

{"errors":[{"code":"UNAUTHORIZED","message":"authentication required","detail":null}]}

:point_up:ググってみた

▼Dockerでpullやrunを行ったときイメージダウンロードができなくなった問題の解決法
https://satoyashiki.hatenablog.com/entry/2017/04/01/175604

:point_up:Dockerの設定でNetworkを変更すれば大丈夫なようです(ysanさんありがとうございます♡)

docker run --name webapp.test -p 5000:7909 -it webapp:Debug
warn: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[35]
      No XML encryptor configured. Key {27592a5c-2404-4081-a0ec-9bb61bd9d7c1} may be persisted to storage in unencrypted form.
Hosting environment: Production
Content root path: /app
Now listening on: http://[::]:7909
Application started. Press Ctrl+C to shut down.

成功(/・ω・)/

簡単に言うと、今使ってるポートから7909にリダイレクトするよ。というチュートリアルでした(簡単すぎる)

まだまだチュートリアルが始まったばかりなので、また勉強になったところがあればシェアしたいと思います:relaxed:
読んでいただきありがとうございました。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0