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)
13775정성태10/19/20248362개발 환경 구성: 728. 윈도우 환경의 개발자를 위한 UTF-8 환경 설정
13774정성태10/18/20247691Linux: 91. Container 환경에서 출력하는 eBPF bpf_get_current_pid_tgid의 pid가 존재하지 않는 이유
13773정성태10/18/20247312Linux: 90. pid 네임스페이스 구성으로 본 WSL 2 + docker-desktop
13772정성태10/17/20247637Linux: 89. pid 네임스페이스 구성으로 본 WSL 2 배포본의 계층 관계
13771정성태10/17/20247469Linux: 88. WSL 2 리눅스 배포본 내에서의 pid 네임스페이스 구성
13770정성태10/17/20248046Linux: 87. ps + grep 조합에서 grep 명령어를 사용한 프로세스를 출력에서 제거하는 방법
13769정성태10/15/20249671Linux: 86. Golang + bpf2go를 사용한 eBPF 기본 예제파일 다운로드1
13768정성태10/15/20248553C/C++: 179. C++ - _O_WTEXT, _O_U16TEXT, _O_U8TEXT의 Unicode stream 모드파일 다운로드2
13767정성태10/14/20246976오류 유형: 929. bpftrace 수행 시 "ERROR: Could not resolve symbol: /proc/self/exe:BEGIN_trigger"
13766정성태10/14/20246145C/C++: 178. C++ - 파일에 대한 Text 모드의 "translated" 동작파일 다운로드1
13765정성태10/12/20248231오류 유형: 928. go build 시 "package maps is not in GOROOT" 오류
13764정성태10/11/20249352Linux: 85. Ubuntu - 원하는 golang 버전 설치
13763정성태10/11/20247246Linux: 84. WSL / Ubuntu 20.04 - bpftool 설치
13762정성태10/11/20247414Linux: 83. WSL / Ubuntu 22.04 - bpftool 설치
13761정성태10/11/20246943오류 유형: 927. WSL / Ubuntu - /usr/include/linux/types.h:5:10: fatal error: 'asm/types.h' file not found
13760정성태10/11/20248582Linux: 82. Ubuntu - clang 최신(stable) 버전 설치
13759정성태10/10/20249738C/C++: 177. C++ - 자유 함수(free function) 및 주소 지정 가능한 함수(addressable function) [6]
13758정성태10/8/20247926오류 유형: 926. dotnet tools를 sudo로 실행하는 경우 command not found
13757정성태10/8/20248530닷넷: 2306. Linux - dotnet tool의 설치 디렉터리가 PATH 환경변수에 자동 등록이 되는 이유
13756정성태10/8/20248735오류 유형: 925. ssh로 docker 접근을 할 때 "... malformed HTTP status code ..." 오류 발생
13755정성태10/7/20249424닷넷: 2305. C# 13 - (9) 메서드 바인딩의 우선순위를 지정하는 OverloadResolutionPriority 특성 도입 (Overload resolution priority)파일 다운로드1
13754정성태10/4/20248117닷넷: 2304. C# 13 - (8) 부분 메서드 정의를 속성 및 인덱서에도 확대파일 다운로드1
13753정성태10/4/20247589Linux: 81. Linux - PATH 환경변수의 적용 규칙
13752정성태10/2/20249119닷넷: 2303. C# 13 - (7) ref struct의 interface 상속 및 제네릭 제약으로 사용 가능 [6]파일 다운로드1
13751정성태10/2/20247290C/C++: 176. C/C++ - ARM64로 포팅할 때 유의할 점
13750정성태10/1/20247100C/C++: 175. C++ - WinMain/wWinMain 호출 전의 CRT 초기화 단계
1  2  3  4  5  6  7  8  9  [10]  11  12  13  14  15  ...