Microsoft MVP성태의 닷넷 이야기
글쓴 사람
정성태 (seongtaejeong at gmail.com)
홈페이지
첨부 파일
 
(연관된 글이 1개 있습니다.)
(시리즈 글이 2개 있습니다.)
개발 환경 구성: 753. CentOS 7 컨테이너 내에서 openssh 서버 호스팅
; https://www.sysnet.pe.kr/2/0/13982

개발 환경 구성: 754. Visual C++ - 리눅스 빌드를 위한 Ubuntu 18 docker 컨테이너 설정
; https://www.sysnet.pe.kr/2/0/13995




Visual C++ - 리눅스 빌드를 위한 Ubuntu 18 docker 컨테이너 설정

자, 그럼 지난 글까지 해서 ssh 서버를 호스팅할 수 있는 CentOS 7 컨테이너를 위한 Dockerfile도 만들었으니,

CentOS 7 컨테이너 내에서 openssh 서버 호스팅
; https://www.sysnet.pe.kr/2/0/13982

유사한 방식으로 Ubuntu 18 컨테이너를 위한 Dockerfile도 다음과 같이 작성할 수 있습니다.

$ cat ubuntu18.dockerfile
FROM ubuntu:18.04

RUN echo 'root:my_temp_pass' | chpasswd

COPY ./ssh /etc/ssh

RUN apt update && apt upgrade -y
RUN apt install openssh-server -y

RUN sed -ri 's/#?PermitRootLogin\s.*$/PermitRootLogin yes/' /etc/ssh/sshd_config

EXPOSE 22

CMD ["/usr/sbin/sshd", "-D"]

이후 실행은 다 아는 방식대로 해주면 됩니다.

// 이미지 만들고,
$ docker build -f ./ubuntu18.dockerfile . -t ubuntu18_dotnet_img

// 컨테이너 실행 (1)
$ docker run --rm -it --name ubuntu18_dotnet_test -p 16022:22 ubuntu18_dotnet_img /bin/bash
$ docker exec -it ubuntu18_dotnet_test /bin/bash
# /usr/sbin/sshd -D

// 컨테이너 실행 (2)
$ docker run --rm -d --name ubuntu18_dotnet_test -p 16022:22 ubuntu18_dotnet_img

$ docker stop ubuntu18_dotnet_test

그런데 Ubuntu 18 컨테이너에서 /usr/sbin/sshd를 실행하면 이런 오류가 발생합니다.

# /usr/sbin/sshd
Missing privilege separation directory: /run/sshd

다행히 아래의 글에 해결책이 있는데요,

SSH failed to start - Missing privilege separation directory: /var/run/sshd [duplicate]
; https://askubuntu.com/questions/1110828/ssh-failed-to-start-missing-privilege-separation-directory-var-run-sshd

미리 sshd 디렉터리를 생성하면 해결이 됩니다.

$ cat ubuntu18.dockerfile
...[생략]...

RUN apt install openssh-server -y

mkdir /var/run/sshd
chmod 0755 /var/run/sshd

...[생략]...

여기까지 반영해 컨테이너를 실행한 다음, 잘 동작하고 있는지 ssh 클라이언트로 접속해 확인까지 완료합니다.

C:\temp> ssh root@192.168.100.50 -p 16022
root@192.168.100.50's password:
Last login: Wed Jul 30 05:33:18 2025 from 192.168.100.20
[root@287641100cd3 ~]#




이 상태에서 Visual C++의 리눅스 빌드를 위한 환경도 마저 구성해 볼 텐데요, 단순히 (Visual C++ 프로젝트에 설정한 Platform Toolset 유형에 따라) clang 또는 g++ 도구를 설치하는 것으로 완료됩니다.

...[생략]...
RUN apt install clang -y
RUN apt install g++ gdb make -y
...[생략]...

바뀐 설정을 반영해 컨테이너를 실행한 다음, 비주얼 스튜디오 측에서는 2개의 변경을 해야 하는데요, 우선 1) Visual Studio의 Tools / Options 창을 통해 "Cross Platform" - "Connection Manager"에서 "Add" 버튼을 눌러 위에서 만든 컨테이너에 대한 연결 정보를 추가합니다. 2) 그다음, Visual C++ 프로젝트의 속성에서 "Remote Build Machine" 설정란에 Connection Manager에서 추가한 연결 정보를 선택합니다.

여기서 재미있는 것은, 저렇게 Visual Studio에서 바꾼 연결 정보는 (vcxproj 파일이 아닌) 형상 관리와 연동하지 않는 *.vcxproj.user 파일에 저장된다는 점입니다. 이로 인해, 버전 관리 서버로부터 받아 빌드하는 서버에서는 Connection Manager를 통해 연결 정보를 새롭게 추가해야 합니다.

C:\temp> ConnectionManager.exe add root@192.168.100.50 --port 16022

C:\temp> ConnectionManager.exe list
Reading stored connections from '%USERPROFILE%\AppData\Local\Microsoft\Linux\User Data\3.0\store.xml'

Connection ID |            Host | Username | Port | Authentication Type
-----------------------------------------------------------------------
  -1782994236 |  192.168.100.50 |     root | 16022 | Password

그리고 또 하나의 문제는, 저 연결 정보 또한 store.xml에 저장하는 것일 뿐, vcxproj 파일에는 -1782994236 ID의 연결 정보를 이용해 빌드하라는 어떠한 속성도 가지고 있지 않아 마찬가지로 빌드에 실패할 수 있습니다. 테스트해 보면, 빌드 대상의 platform에 해당하는 연결 정보가 하나만 있다면 자동 선택되지만 다중으로 있는 경우에는 (규칙은 알 수 없지만) 특정 연결 정보가 임의로 선택되기 때문에 빌드에 실패할 수 있습니다.

이런 경우, store.xml에 등록된 특정 연결 정보를 선택하도록 msbuild 인자에 /p:RemoteTarget 옵션으로 전달할 수 있습니다. 예를 들어, 완벽하게 모든 정보를 전달해도 되지만,

msbuild.exe testapp.vcxproj /p:RemoteTarget="-1782994236;192.168.100.50 (username=, port=16022, authentication=Password)" /p:Platform=x64;Configuration=Release /t:Rebuild

Connection ID 값만 전달해도 충분하므로 간단하게 다음과 같이 설정할 수 있습니다.

msbuild.exe testapp.vcxproj /p:RemoteTarget="-1782994236" /p:Platform=x64;Configuration=Release /t:Rebuild




혹시 openssh-server 설치 시 이런 질문 단계가 나온다면?

// 미리 /etc/ssh에 키 파일을 복사한 후,

$ apt install openssh-server -y
...[생략]...
Configuration file '/etc/ssh/moduli'
 ==> File on system created by you or by a script.
 ==> File also in package provided by package maintainer.
   What would you like to do about it ?  Your options are:
    Y or I  : install the package maintainer's version
    N or O  : keep your currently-installed version
      D     : show the differences between the versions
      Z     : start a shell to examine the situation
 The default action is to keep your current version.
*** moduli (Y/I/N/O/D/Z) [default=N] ?
Progress: [ 94%] [####################################################################################################.......]

현재 /etc/ssh 디렉터리에 키 파일은 물론이고 moduli 파일도 있는 상태에서 설치했기 때문입니다. 따라서, 위와 같은 질문이 나오면 덮어쓰면 되고, 혹은 미리 /etc/ssh/moduli 파일을 삭제하면 저런 질문이 나오지 않습니다.




정리해 보면, dockerfile은 대충 이런 식으로 구성할 수 있습니다.

FROM ubuntu:18.04

RUN echo 'root:my_temp_pass' | chpasswd

COPY ./ssh /etc/ssh

RUN apt update && apt upgrade -y
RUN apt install openssh-server unzip curl net-tools lsb-release -y
RUN apt install clang -y
RUN apt install g++ gdb make -y

RUN mkdir /var/run/sshd
RUN chmod 0755 /var/run/sshd

RUN sed -ri 's/#?PermitRootLogin\s.*$/PermitRootLogin yes/' /etc/ssh/sshd_config

EXPOSE 22

CMD ["/usr/sbin/sshd", "-D"]

그렇다면, 혹시나 왜 굳이 최신 버전의 Ubuntu가 아닌 18.04 버전을 사용하는가 궁금할 수 있는데요, 그 이유는 빌드한 바이너리의 호환성을 높이기 위해서입니다.




[이 글에 대해서 여러분들과 의견을 공유하고 싶습니다. 틀리거나 미흡한 부분 또는 의문 사항이 있으시면 언제든 댓글 남겨주십시오.]

[연관 글]






[최초 등록일: ]
[최종 수정일: 8/13/2025]

Creative Commons License
이 저작물은 크리에이티브 커먼즈 코리아 저작자표시-비영리-변경금지 2.0 대한민국 라이센스에 따라 이용하실 수 있습니다.
by SeongTae Jeong, mailto:techsharer at outlook.com

비밀번호

댓글 작성자
 




... [16]  17  18  19  20  21  22  23  24  25  26  27  28  29  30  ...
NoWriterDateCnt.TitleFile(s)
13623정성태5/11/202410217닷넷: 2261. C# - 구글 OAuth의 JWT (JSON Web Tokens) 해석파일 다운로드1
13622정성태5/10/202412983닷넷: 2260. C# - Google 로그인 연동 (ASP.NET 예제)파일 다운로드1
13621정성태5/10/202411842오류 유형: 903. IISExpress - Failed to register URL "..." for site "..." application "/". Error description: Cannot create a file when that file already exists. (0x800700b7)
13620정성태5/9/202411002VS.NET IDE: 190. Visual Studio가 node.exe를 경유해 Edge.exe를 띄우는 경우
13619정성태5/7/202411788닷넷: 2259. C# - decimal 저장소의 비트 구조 [2]파일 다운로드1
13618정성태5/6/202410384닷넷: 2258. C# - double (배정도 실수) 저장소의 비트 구조파일 다운로드1
13617정성태5/5/202412906닷넷: 2257. C# - float (단정도 실수) 저장소의 비트 구조파일 다운로드1
13616정성태5/3/202410392닷넷: 2256. ASP.NET Core 웹 사이트의 HTTP/HTTPS + Dual mode Socket (IPv4/IPv6) 지원 방법파일 다운로드1
13615정성태5/3/202413028닷넷: 2255. C# 배열을 Numpy ndarray 배열과 상호 변환
13614정성태5/2/202412844닷넷: 2254. C# - COM 인터페이스의 상속 시 중복으로 메서드를 선언
13613정성태5/1/202410611닷넷: 2253. C# - Video Capture 장치(Camera) 열거 및 지원 포맷 조회파일 다운로드1
13612정성태4/30/202412331오류 유형: 902. Visual Studio - error MSB3021: Unable to copy file
13611정성태4/29/202410839닷넷: 2252. C# - GUID 타입 전용의 UnmanagedType.LPStruct - 두 번째 이야기파일 다운로드1
13610정성태4/28/202412386닷넷: 2251. C# - 제네릭 인자를 가진 타입을 생성하는 방법 - 두 번째 이야기
13609정성태4/27/202412036닷넷: 2250. PInvoke 호출 시 참조 타입(class)을 마샬링하는 [IN], [OUT] 특성파일 다운로드1
13608정성태4/26/202412906닷넷: 2249. C# - 부모의 필드/프로퍼티에 대해 서로 다른 자식 클래스 간에 Reflection 접근이 동작할까요?파일 다운로드1
13607정성태4/25/202412916닷넷: 2248. C# - 인터페이스 타입의 다중 포인터를 인자로 갖는 C/C++ 함수 연동
13606정성태4/24/202412966닷넷: 2247. C# - tensorflow 연동 (MNIST 예제)파일 다운로드1
13605정성태4/23/202414363닷넷: 2246. C# - Python.NET을 이용한 파이썬 소스코드 연동파일 다운로드1
13604정성태4/22/202410498오류 유형: 901. Visual Studio - Unable to set the next statement. Set next statement cannot be used in '[Exception]' call stack frames.
13603정성태4/21/202413436닷넷: 2245. C# - IronPython을 이용한 파이썬 소스코드 연동파일 다운로드1
13602정성태4/20/202411632닷넷: 2244. C# - PCM 오디오 데이터를 연속(Streaming) 재생 (Windows Multimedia)파일 다운로드1
13601정성태4/19/202412025닷넷: 2243. C# - PCM 사운드 재생(NAudio)파일 다운로드1
13600정성태4/18/202413514닷넷: 2242. C# - 관리 스레드와 비관리 스레드
13599정성태4/17/202413212닷넷: 2241. C# - WAV 파일의 PCM 사운드 재생(Windows Multimedia)파일 다운로드1
13598정성태4/16/202413338닷넷: 2240. C# - WAV 파일 포맷 + LIST 헤더파일 다운로드2
... [16]  17  18  19  20  21  22  23  24  25  26  27  28  29  30  ...