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)
13925정성태5/12/20253890닷넷: 2333. C# - (Console 유형의 프로젝트에서) Clipboard 연동파일 다운로드1
13924정성태5/8/20253235닷넷: 2332. C# - (JetBrains Omea Reader 대상으로) 런타임 시에 메서드 가로채기 [2]파일 다운로드1
13923정성태5/5/20252697스크립트: 74. 파이썬 - C# - Python.NET의 RunSimpleScript, Exec, Eval 차이점파일 다운로드1
13922정성태5/3/20253911스크립트: 73. 파이썬 - Windows embeddable package 버전에서 tkinter 환경 구성
13921정성태5/3/20254184오류 유형: 952. 듀얼 채널 메모리 정렬을 지키지 않은 컴퓨터의 Windows 비정상 종료 현상(Blue Screen) [2]
13920정성태5/3/20254648오류 유형: 951. Typed DataSet 생성 중 "Failed to open a connection to the database" 오류
13919정성태5/2/20253688VS.NET IDE: 201. C# - Typed DataSet(XSD)를 위한 연결 문자열 암호화 [1]파일 다운로드1
13918정성태5/2/20254557VS.NET IDE: 200. C# - app.config 파일의 출력을 Configuration(Debug/Release)에 따라 제어하는 방법파일 다운로드1
13917정성태4/30/20253211VS.NET IDE: 199. Directory.Build.props에 정의한 속성에 대해 Condition 제약으로 값을 변경하는 방법
13916정성태4/23/20252607디버깅 기술: 221. WinDbg 분석 사례 - ASP.NET HttpCookieCollection을 다중 스레드에서 사용할 경우 무한 루프 현상 - 두 번째 이야기
13915정성태4/13/20254669닷넷: 2331. C# - 실행 시에 메서드 가로채기 (.NET 9)파일 다운로드1
13914정성태4/11/20255190디버깅 기술: 220. windbg 분석 사례 - x86 ASP.NET 웹 응용 프로그램의 CPU 100% 현상 (4)
13913정성태4/10/20253089오류 유형: 950. Process Explorer - 64비트 윈도우에서 32비트 프로세스의 덤프를 뜰 때 "Error writing dump file: Access is denied." 오류
13912정성태4/9/20252762닷넷: 2330. C# - 실행 시에 메서드 가로채기 (.NET 5 ~ .NET 8)파일 다운로드1
13911정성태4/8/20253400오류 유형: 949. WinDbg - .NET Core/5+ 응용 프로그램 디버깅 시 sos 확장을 자동으로 로드하지 못하는 문제
13910정성태4/8/20253446디버깅 기술: 219. WinDbg - 명령어 내에서 환경 변수 사용법
13909정성태4/7/20255249닷넷: 2329. C# - 실행 시에 메서드 가로채기 (.NET Framework 4.8)파일 다운로드1
13908정성태4/2/20255421닷넷: 2328. C# - MailKit: SMTP, POP3, IMAP 지원 라이브러리
13907정성태3/29/20255773VS.NET IDE: 198. (OneDrive, Dropbox 등의 공유 디렉터리에 있는) C# 프로젝트의 출력 경로 변경하기
13906정성태3/27/20255962닷넷: 2327. C# - 초기화되지 않은 메모리에 접근하는 버그?파일 다운로드1
13905정성태3/26/20255950Windows: 281. C++ - Windows / Critical Section의 안정화를 위해 도입된 "Keyed Event"파일 다운로드1
13904정성태3/25/20254806디버깅 기술: 218. Windbg로 살펴보는 Win32 Critical Section파일 다운로드1
13903정성태3/24/20253583VS.NET IDE: 197. (OneDrive, Dropbox 등의 공유 디렉터리에 있는) C++ 프로젝트의 출력 경로 변경하기
13902정성태3/24/20254280개발 환경 구성: 742. Oracle - 테스트용 hr 계정 및 데이터 생성파일 다운로드1
13901정성태3/9/20254607Windows: 280. Hyper-V의 3가지 Thread Scheduler (Classic, Core, Root)
13900정성태3/8/20256101스크립트: 72. 파이썬 - SQLAlchemy + oracledb 연동
1  2  3  [4]  5  6  7  8  9  10  11  12  13  14  15  ...