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

비밀번호

댓글 작성자
 




1  2  3  4  5  6  [7]  8  9  10  11  12  13  14  15  ...
NoWriterDateCnt.TitleFile(s)
13850정성태12/23/20248230오류 유형: 940. "Application Information" 서비스를 중지한 경우, "This file does not have an app associated with it for performing this action."
13849정성태12/20/20248153디버깅 기술: 210. Windbg - 논리(가상) 주소를 Segmentation을 거쳐 선형 주소로 변경
13848정성태12/18/20247303디버깅 기술: 209. Windbg로 알아보는 Prototype PTE파일 다운로드2
13847정성태12/18/20247108오류 유형: 939. golang - 빌드 시 "unknown directive: toolchain" 오류 빌드 시 이런 오류가 발생한다면?
13846정성태12/17/20248029디버깅 기술: 208. Windbg로 알아보는 Trans/Soft PTE와 2가지 Page Fault 유형파일 다운로드1
13845정성태12/16/20246100디버깅 기술: 207. Windbg로 알아보는 PTE (_MMPTE)
13844정성태12/14/20248991디버깅 기술: 206. Windbg로 알아보는 PFN (_MMPFN)파일 다운로드1
13843정성태12/13/20246424오류 유형: 938. Docker container 내에서 빌드 시 error MSB3021: Unable to copy file "..." to "...". Access to the path '...' is denied.
13842정성태12/12/20246622디버깅 기술: 205. Windbg - KPCR, KPRCB
13841정성태12/11/20247463오류 유형: 937. error MSB4044: The "ValidateValidArchitecture" task was not given a value for the required parameter "RemoteTarget"
13840정성태12/11/20246433오류 유형: 936. msbuild - Your project file doesn't list 'win' as a "RuntimeIdentifier"
13839정성태12/11/20247986오류 유형: 936. msbuild - error CS1617: Invalid option '12.0' for /langversion. Use '/langversion:?' to list supported values.
13838정성태12/4/20247417오류 유형: 935. Windbg - Breakpoint 0's offset expression evaluation failed.
13837정성태12/3/20248751디버깅 기술: 204. Windbg - 윈도우 핸들 테이블 (3) - Windows 10 이상인 경우
13836정성태12/3/20246340디버깅 기술: 203. Windbg - x64 가상 주소를 물리 주소로 변환 (페이지 크기가 2MB인 경우)
13835정성태12/2/20248712오류 유형: 934. Azure - rm: cannot remove '...': Directory not empty
13834정성태11/29/20248465Windows: 275. C# - CUI 애플리케이션과 Console 윈도우 (Windows 10 미만의 Classic Console 모드인 경우) [1]파일 다운로드1
13833정성태11/29/20247713개발 환경 구성: 737. Azure Web App에서 Scale-out으로 늘어난 리눅스 인스턴스에 SSH 접속하는 방법
13832정성태11/27/20247207Windows: 274. Windows 7부터 도입한 conhost.exe
13831정성태11/27/20246080Linux: 111. eBPF - BPF_MAP_TYPE_PERF_EVENT_ARRAY, BPF_MAP_TYPE_RINGBUF에 대한 다양한 용어들
13830정성태11/25/20248612개발 환경 구성: 736. 파이썬 웹 앱을 Azure App Service에 배포하기
13829정성태11/25/20248705스크립트: 67. 파이썬 - Windows 버전에서 함께 설치되는 py.exe
13828정성태11/25/20246381개발 환경 구성: 735. Azure - 압축 파일을 이용한 web app 배포 시 디렉터리 구분이 안 되는 문제파일 다운로드1
13827정성태11/25/20247432Windows: 273. Windows 환경의 파일 압축 방법 (tar, Compress-Archive)
13826정성태11/21/20247888닷넷: 2313. C# - (비밀번호 등의) Console로부터 입력받을 때 문자열 출력 숨기기(echo 끄기)파일 다운로드1
13825정성태11/21/20249196Linux: 110. eBPF / bpf2go - BPF_RINGBUF_OUTPUT / BPF_MAP_TYPE_RINGBUF 사용법
1  2  3  4  5  6  [7]  8  9  10  11  12  13  14  15  ...