[user01@vmcentos7 src]$ sudo docker build -t reservationsystem .
Sending build context to Docker daemon 29.7kB
Step 1/12 : FROM mcr.microsoft.com/dotnet/core/sdk:2.2
2.2: Pulling from dotnet/core/sdk
146bd6a88618: Pull complete
9935d0c62ace: Pull complete
db0efb86e806: Pull complete
e705a4c4fd31: Pull complete
563ac9aa7c80: Pull complete
9db5b5c16f62: Pull complete
ff05a093e8aa: Pull complete
Digest: sha256:42699bba2fe4545dd753694499e6db08478ba5b3bcc34b929e7e324d4c115449
Status: Downloaded newer image for mcr.microsoft.com/dotnet/core/sdk:2.2
---> 2357b6790b9d
Step 2/12 : WORKDIR /src
---> Running in c70d33cb8cd8
Removing intermediate container c70d33cb8cd8
---> c0dd2646e016
Step 3/12 : COPY ["HotelReservationSystem/HotelReservationSystem.csproj", "HotelReservationSystem/"]
---> fce6cab59dbd
Step 4/12 : COPY ["HotelReservationSystemTypes/HotelReservationSystemTypes.csproj", "HotelReservationSystemTypes/"]
---> f2d508915249
Step 5/12 : RUN dotnet restore "HotelReservationSystem/HotelReservationSystem.csproj"
---> Running in 2590e1950645
Restore completed in 5.65 sec for /src/HotelReservationSystemTypes/HotelReservationSystemTypes.csproj.
Restore completed in 12.59 sec for /src/HotelReservationSystem/HotelReservationSystem.csproj.
Removing intermediate container 2590e1950645
---> c50f64bc38c2
Step 6/12 : COPY . .
---> cca7acd65a4f
Step 7/12 : WORKDIR "/src/HotelReservationSystem"
---> Running in c0246f4fca75
Removing intermediate container c0246f4fca75
---> 6ed5660d8927
Step 8/12 : RUN dotnet build "HotelReservationSystem.csproj" -c Release -o /app
---> Running in e937623d5034
Microsoft (R) Build Engine version 16.0.450+ga8dc7f1d34 for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.
Restore completed in 68.33 ms for /src/HotelReservationSystemTypes/HotelReservationSystemTypes.csproj.
Restore completed in 87.37 ms for /src/HotelReservationSystem/HotelReservationSystem.csproj.
HotelReservationSystemTypes -> /app/HotelReservationSystemTypes.dll
HotelReservationSystem -> /app/HotelReservationSystem.dll
Build succeeded.
0 Warning(s)
0 Error(s)
Time Elapsed 00:00:03.95
Removing intermediate container e937623d5034
---> efaef60407e4
Step 9/12 : RUN dotnet publish "HotelReservationSystem.csproj" -c Release -o /app
---> Running in 02b106ff3c30
Microsoft (R) Build Engine version 16.0.450+ga8dc7f1d34 for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.
Restore completed in 73.59 ms for /src/HotelReservationSystemTypes/HotelReservationSystemTypes.csproj.
Restore completed in 90.51 ms for /src/HotelReservationSystem/HotelReservationSystem.csproj.
HotelReservationSystemTypes -> /src/HotelReservationSystemTypes/bin/Release/netcoreapp2.1/HotelReservationSystemTypes.dll
HotelReservationSystem -> /src/HotelReservationSystem/bin/Release/netcoreapp2.1/HotelReservationSystem.dll
HotelReservationSystem -> /app/
Removing intermediate container 02b106ff3c30
---> 77f852b5e973
Step 10/12 : EXPOSE 80
---> Running in 08cab1c836e5
Removing intermediate container 08cab1c836e5
---> 478f4cc63f1f
Step 11/12 : WORKDIR /app
---> Running in 95ebc8344212
Removing intermediate container 95ebc8344212
---> 4621ea0ae72b
Step 12/12 : ENTRYPOINT ["dotnet", "HotelReservationSystem.dll"]
---> Running in 4bb57898fcfb
Removing intermediate container 4bb57898fcfb
---> 14f55c7ee119
Successfully built 14f55c7ee119
Successfully tagged reservationsystem:latest
完了したので、以下のコマンドでできたイメージを確認します。
sudo docker image list
[user01@vmcentos7 ~]$ sudo docker image list
REPOSITORY TAG IMAGE ID CREATED SIZE
reservationsystem latest 14f55c7ee119 15 hours ago 1.87GB
ubuntu latest 1d622ef86b13 5 weeks ago 73.9MB
hello-world latest bf756fb1ae65 4 months ago 13.3kB
mcr.microsoft.com/dotnet/core/sdk 2.2 2357b6790b9d 5 months ago 1.74GB
[user01@vmcentos7 src]$ sudo docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
2501767b06da reservationsystem "dotnet HotelReserva…" 8 minutes ago Up 8 minutes 0.0.0.0:8080->80/tcp reservations
コンテナがアップしていることの確認が取れたので実際にWEBブラウザでアクセスしてみたいと思います。
今回はAzureにある仮想マシンでコンテナを実行しているので、そのアドレスにアクセスします。
http://fqdn:8080/api/reservations/1
実行した結果、 Web アプリによって予約数が 1 のデータを含む、JSON ドキュメントが表示されましたのでうまくいきました。
[user01@vmcentos7 src]$ sudo docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
2501767b06da reservationsystem "dotnet HotelReserva…" 11 minutes ago Exited (0) 40 seconds ago reservations
[user01@vmcentos7 src]$ sudo docker login ymstctrreg.azurecr.io
Username: ymstctrreg
Password:
WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
sudo docker image tag reservationsystem reservationsystem:v1
[user01@vmcentos7 src]$ sudo docker image tag reservationsystem reservationsystem:v1
[user01@vmcentos7 src]$ sudo docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
reservationsystem latest 14f55c7ee119 17 hours ago 1.87GB
reservationsystem v1 14f55c7ee119 17 hours ago 1.87GB
ローカルに「v1」タグ付けしたDockerイメージが確認できました。
コンテナーレジストリにもタグをつける
Azureコンテナーレジストリにもリポジトリを作成しタグをつけます。
sudo docker tag reservationsystem:v1 ymstctrreg.azurecr.io/reservationsystem:v1