728x90
반응형
1. Docker 설치확인
PS C:\Project\Microservices\PlatformService> docker --version
Docker version 20.10.14, build a224086
설치되어 있지 않으면 Docker Desktop을 설치한다.
2022.05.03 - [Docker] - Windows 10] Docker Desktop 설치
2. Kubernetes 설치확인
Settings > Kubernetes 에서 Enable Kubernetes 체크확인 후, 되어 있지 않으면 체크 후 Apply & Restart 한다.
3. Docker Hub 계정 생성
4. VS Code에 Docker Extension 설치
5. Dockerfile
# https://hub.docker.com/_/microsoft-dotnet
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build-env
WORKDIR /app
# copy csproj and restore as distinct layers
COPY *.csproj ./
RUN dotnet restore
# copy everything else and build app
COPY . ./aspnetapp/
RUN dotnet publish -c release -o out
# final stage/image
FROM mcr.microsoft.com/dotnet/aspnet:6.0
WORKDIR /app
COPY --from=build-env /app/out .
ENTRYPOINT ["dotnet", "PlatformService.dll"]
6. Create Image
PS C:\Project\Microservices\PlatformService> docker build -t <docker hub id>/platformservice .
[+] Building 4.7s (15/15) FINISHED
=> [internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 482B 0.0s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> [internal] load metadata for mcr.microsoft.com/dotnet/aspnet:6.0 0.1s
=> [internal] load metadata for mcr.microsoft.com/dotnet/sdk:6.0 0.1s
=> [stage-1 1/3] FROM mcr.microsoft.com/dotnet/aspnet:6.0@sha256:211c84ef15e0d2bc77c8d37ea1d936ecf2f4edd11ffd260b11ec9371db63dd3d 0.0s
=> [build-env 1/6] FROM mcr.microsoft.com/dotnet/sdk:6.0@sha256:d5f9090e564d391c0f00005bc06c74d1f97ccc59d561d3e161d7d3e3acdcd0ca 0.0s
=> [internal] load build context 0.1s
=> => transferring context: 9.76kB 0.1s
=> CACHED [stage-1 2/3] WORKDIR /app 0.0s
=> CACHED [build-env 2/6] WORKDIR /app 0.0s
=> CACHED [build-env 3/6] COPY *.csproj ./ 0.0s
=> CACHED [build-env 4/6] RUN dotnet restore 0.0s
=> [build-env 5/6] COPY . ./ 0.1s
=> [build-env 6/6] RUN dotnet publish -c Release -o out 4.0s
=> [stage-1 3/3] COPY --from=build-env /app/out . 0.1s
=> exporting to image 0.1s
=> => exporting layers 0.1s
=> => writing image sha256:006a61c2e93a165e25b7bb12180d5c58d9b38f5b482380e4cd2562e4b1f255d6 0.0s
=> => naming to docker.io/<docker hub id>/platformservice 0.0s
Use 'docker scan' to run Snyk tests against images to find vulnerabilities and learn how to fix them
7. Image 실행
PS C:\Project\Microservices\PlatformService> docker run -p 8080:80 -d <docker hub id>/platformservice
Container로 실행된다.
PS C:\Project\Microservices\PlatformService> docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
d53dca9d8644 <docker hub id>/platformservice "dotnet PlatformServ…" 2 minutes ago Up 2 minutes 0.0.0.0:8080->80/tcp clever_visvesvaraya
아래 명령어를 한번 더 실행하면, 별도의 Container가 추가된다.
PS C:\Project\Microservices\PlatformService> docker run -p 8080:80 -d <docker hub id>/platformservice
8. Docker Hub로 Image Push
PS C:\Project\Microservices\PlatformService> docker login
Login with your Docker ID to push and pull images from Docker Hub. If you don't have a Docker ID, head over to https://hub.docker.com to create one.
Username:
Password:
Login Succeeded
Logging in with your password grants your terminal complete access to your account.
For better security, log in with a limited-privilege personal access token. Learn more at https://docs.docker.com/go/access-tokens/
PS C:\Project\Microservices\PlatformService> docker push <docker hub id>/platformservice
Using default tag: latest
The push refers to repository [docker.io/<docker hub id>/platformservice]
eeedfe68b540: Pushed
f4d0128f9412: Pushed
70c482798b89: Pushed
79c360779f60: Pushed
d2557e8ba797: Pushed
5a8a15f6e841: Pushed
ed7b0ef3bf5b: Pushed
latest: digest: sha256:f63587bb8b981167741fdef49e53413237634cb7b966d51f3ccb5fafd4a300da size: 1789
728x90
반응형
'.NET Microservices' 카테고리의 다른 글
.NET Microservices] 3. 샘플 프로젝트 - PlatformService (0) | 2023.04.18 |
---|---|
.NET Microservices] 2. 샘플 프로젝트 - 아키텍처 (0) | 2023.04.17 |
.NET Microservices] 1. 소개 (0) | 2023.02.03 |
댓글