성태의 닷넷 이야기
홈 주인
모아 놓은 자료
프로그래밍
질문/답변
사용자 관리
사용자
메뉴
아티클
외부 아티클
유용한 코드
온라인 기능
MathJax 입력기
최근 덧글
[정성태] Java - How to use the Foreign Funct...
[정성태] 제가 큰 실수를 했군요. ^^; Delegate를 통한 Bein...
[정성태] Working with Rust Libraries from C#...
[정성태] Detecting blocking calls using asyn...
[정성태] 아쉽게도, 커뮤니티는 아니고 개인 블로그입니다. ^^
[정성태] 질문이 잘 이해가 안 됩니다. 우선, 해당 소스코드에서 ILis...
[양승조
] var대신 dinamic으로 선언해서 해결은 했습니다. 맞는 해...
[양승조
] 또 막혔습니다. ㅠㅠ var list = props[i].Ge...
[양승조
] 아. 감사합니다. 어제는 안됐던것 같은데....정신을 차려야겠네...
[정성태] "props[i].GetValue(props[i])" 코드에서 ...
글쓰기
제목
이름
암호
전자우편
HTML
홈페이지
유형
제니퍼 .NET
닷넷
COM 개체 관련
스크립트
VC++
VS.NET IDE
Windows
Team Foundation Server
디버깅 기술
오류 유형
개발 환경 구성
웹
기타
Linux
Java
DDK
Math
Phone
Graphics
사물인터넷
부모글 보이기/감추기
내용
<div style='display: inline'> <h1 style='font-family: Malgun Gothic, Consolas; font-size: 20pt; color: #006699; text-align: center; font-weight: bold'>.NET Core 용 container 이미지 만들 때 unzip이 필요한 경우</h1> <p> 닷넷 용 컨테이너 이미지를 만드는 경우 대개 마이크로소프트의 권장에 따라,<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > Visual Studio - ASP.NET Core Web Application의 "Enable Docker Support" 옵션으로 달라지는 점 ; <a target='tab' href='https://www.sysnet.pe.kr/2/0/12171'>https://www.sysnet.pe.kr/2/0/12171</a> </pre> <br /> mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim이나, mcr.microsoft.com/dotnet/core/sdk:3.1-buster를 사용하게 될 것입니다. 이런 이미지들은 마이크로소프트가 경량화시킨 것이기 때문에 - 특히 slim 버전의 경우 - Dockerfile 내의 명령어 수행에 'unzip' 같은 것을 포함하면 다음과 같은 오류가 발생합니다.<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > Step 15/20 : RUN unzip test.zip ---> Running in 0e9904a5c1e0 /bin/sh: 1: unzip: not found <span style='color: blue; font-weight: bold'>The command '/bin/sh -c unzip test.zip' returned a non-zero code: 127</span> ERROR: Job failed: exit code 127 </pre> <br /> 검색해 보면,<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > Debug .NET Core with docker containers ; <a target='tab' href='https://github.com/microsoft/generator-docker/issues/130'>https://github.com/microsoft/generator-docker/issues/130</a> </pre> <br /> 아예 unzip을 이미지 내에 설치하도록 하는 방법이 있습니다. ^^<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > RUN apt-get update && apt-get install -y --no-install-recommends unzip && rm -rf /var/lib/apt/lists/* </pre> <br /> 최종 이미지를 이렇게 만드는 것은 바람직하지 않으니, "<a target='tab' href='https://www.sysnet.pe.kr/2/0/12171'>Visual Studio - ASP.NET Core Web Application의 "Enable Docker Support" 옵션으로 달라지는 점</a>" 글에서도 다뤘던 pubilsh 단계에서 처리하는 것이 좋을 텐데요,<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > ...[생략]... FROM build AS publish RUN dotnet publish "ConsoleApp1.csproj" -c Release -o /app/publish <span style='color: blue; font-weight: bold'>RUN apt-get update && apt-get install -y --no-install-recommends unzip && rm -rf /var/lib/apt/lists/*</span> ...[생략]... </pre> <br /> 따라서 프로젝트에 "test.zip" 파일이 있어 이를 처리하려고 한다면 다음과 같은 식으로 압축 해제를 할 수 있습니다.<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > ...[생략]... FROM build AS publish RUN dotnet publish "ConsoleApp2.csproj" -c Release -o /app/publish RUN apt-get update && apt-get install -y --no-install-recommends unzip && rm -rf /var/lib/apt/lists/* <span style='color: blue; font-weight: bold'>WORKDIR /extracted COPY ./ConsoleApp1/test.zip . RUN unzip test.zip</span> FROM base AS final WORKDIR /app COPY --from=publish /app/publish . <span style='color: blue; font-weight: bold'>COPY --from=publish /extracted ./extracted/</span> ENTRYPOINT ["dotnet", "ConsoleApp2.dll"] </pre> <br /> <hr style='width: 50%' /><br /> <br /> 그런데, apt-get... 명령어가 "mcr.microsoft.com/dotnet/core/sdk:2.1-stretch" 이미지를 대상으로는 수행이 되지만, .NET Core 3.1 용 이미지인 "mcr.microsoft.com/dotnet/core/sdk:3.1-buster"에서는 현재 다음과 같은 식의 오류가 발생합니다.<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > 1>Step 12/18 : RUN apt-get update && apt-get install -y --no-install-recommends unzip && rm -rf /var/lib/apt/lists/* 1> ---> Running in cd78a969cc77 1>Get:1 http://deb.debian.org/debian buster InRelease [122 kB] 1>Get:2 http://security.debian.org/debian-security buster/updates InRelease [65.4 kB] 1>Get:3 http://deb.debian.org/debian buster-updates InRelease [49.3 kB] 1>Get:4 http://deb.debian.org/debian buster/main amd64 Packages [7907 kB] 1>Reading package lists... 1>E: Release file for http://security.debian.org/debian-security/dists/buster/updates/InRelease is not valid yet (invalid for another 10d 9h 28min 51s). Updates for this repository will not be applied. 1>E: Release file for http://deb.debian.org/debian/dists/buster-updates/InRelease is not valid yet (invalid for another 10d 0h 5min 14s). Updates for this repository will not be applied. 1>Removing intermediate container cd78a969cc77 1>The command '/bin/sh -c apt-get update && apt-get install -y --no-install-recommends unzip && rm -rf /var/lib/apt/lists/*' returned a non-zero code: 100 1>f:\temp\consoleapp1\dockerfile : error CTC1014: Docker command failed with exit code 100. 1>f:\temp\consoleapp1\dockerfile : error CTC1014: The command '/bin/sh -c apt-get update && apt-get install -y --no-install-recommends unzip && rm -rf /var/lib/apt/lists/*' returned a non-zero code: 100 1>Done building project "ConsoleApp1.csproj" -- FAILED. </pre> <br /> 실제로 해당 sdk:3.1-buster 이미지를 직접 실행해도,<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > c:\temp> docker run --name test -it mcr.microsoft.com/dotnet/core/sdk:3.1-buster /bin/bash root@f133b3e361aa:/# apt-get update && apt-get install -y --no-install-recommends unzip && rm -rf /var/lib/apt/lists/* Get:1 http://security.debian.org/debian-security buster/updates InRelease [65.4 kB] Get:2 http://deb.debian.org/debian buster InRelease [122 kB] Get:3 http://deb.debian.org/debian buster-updates InRelease [49.3 kB] Get:4 http://deb.debian.org/debian buster/main amd64 Packages [7907 kB] Reading package lists... Done E: Release file for http://security.debian.org/debian-security/dists/buster/updates/InRelease is not valid yet (invalid for another 10d 9h 15min 14s). Updates for this repository will not be applied. E: Release file for http://deb.debian.org/debian/dists/buster-updates/InRelease is not valid yet (invalid for another 9d 23h 51min 36s). Updates for this repository will not be applied. </pre> <br /> 오류가 발생하기는 마찬가지입니다. 일단, 이런 상황에서는 또 다른 stage 하나를 추가해서 처리하면 됩니다. 기반 이미지는... 그냥 ^^ 익숙한 걸로 2.1로 잘 되었으니 3.1의 경우 (에러가 발생한다면) 다음과 같이 우회해서 처리할 수 있습니다.<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > FROM mcr.microsoft.com/dotnet/core/runtime:3.1-buster-slim AS base WORKDIR /app <span style='color: blue; font-weight: bold'>FROM mcr.microsoft.com/dotnet/core/sdk:2.1-stretch AS unziphelper RUN apt-get update && apt-get install -y --no-install-recommends unzip && rm -rf /var/lib/apt/lists/* WORKDIR /extracted COPY ./ConsoleApp1/test.zip . RUN unzip test.zip</span> FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build WORKDIR /src COPY ["ConsoleApp1/ConsoleApp1.csproj", "ConsoleApp1/"] RUN dotnet restore "ConsoleApp1/ConsoleApp1.csproj" COPY . . WORKDIR "/src/ConsoleApp1" RUN dotnet build "ConsoleApp1.csproj" -c Release -o /app/build FROM build AS publish RUN dotnet publish "ConsoleApp1.csproj" -c Release -o /app/publish FROM base AS final WORKDIR /app COPY --from=publish /app/publish . <span style='color: blue; font-weight: bold'>COPY --from=unziphelper /extracted ./extracted</span> ENTRYPOINT ["dotnet", "ConsoleApp1.dll"] </pre> <br /> <hr style='width: 50%' /><br /> <br /> 참고로, 비주얼 스튜디오의 "Build Docker Image"를 메뉴로 이미지를 만들다 보면 <none>에 해당하는 항목이 쌓일 수 있습니다. 그런 경우 다음의 명령어로 지워주면 끝!<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > // <a target='tab' href='https://www.sysnet.pe.kr/2/0/11738'>https://www.sysnet.pe.kr/2/0/11738</a> // <a target='tab' href='https://www.sysnet.pe.kr/2/0/11708'>https://www.sysnet.pe.kr/2/0/11708</a> FOR /F %i IN ('docker images -f "dangling=true" -q') do docker rmi %i </pre> </p><br /> <br /><hr /><span style='color: Maroon'>[이 글에 대해서 여러분들과 의견을 공유하고 싶습니다. 틀리거나 미흡한 부분 또는 의문 사항이 있으시면 언제든 댓글 남겨주십시오.]</span> </div>
첨부파일
스팸 방지용 인증 번호
4467
(왼쪽의 숫자를 입력해야 합니다.)