Microsoft MVP성태의 닷넷 이야기
글쓴 사람
정성태 (seongtaejeong at gmail.com)
홈페이지
첨부 파일
 

Linux - snap 패키지 관리자로 설치한 소프트웨어의 디렉터리 접근 제한

지난 글에서,

ERROR: failed to solve: failed to read dockerfile: open Dockerfile: no such file or directory
; https://www.sysnet.pe.kr/2/0/14000

snap으로 설치한 docker의 경우 Dockerfile을 읽어내지 못하는 현상을 다뤘는데요, 이유를 알아냈습니다. ^^

Snap documentation
; https://snapcraft.io/docs

뭐랄까, 쉽게 말해 docker 컨테이너와 같은 격리를 "snap으로 설치한 응용 프로그램"(너무 길어서 이후로 그냥 app이라고 부르겠습니다.)에 대해 제공하는 것과 유사하다고 보면 될 것 같습니다. 즉, 일종의 sandbox 환경을 제공하기 때문에 app의 호스트 접근이 자유롭지 않은 부분이 있는 건데요, 위에서 실습한 Dockerfile을 읽어내지 못하는 것도 그중 하나입니다.

이해를 돕기 위해 상황을 다시 재현을 해볼까요?

우선, 루트 디렉터리 하위에 "/temp"라는 디렉터리를 하나 만들고 그 안에 dockerfile을 만들어 빌드해 봅니다.

$ pwd
/temp

$ cat test.dockerfile
FROM ubuntu:18.04

RUN echo TEST

$ docker build -f test.dockerfile -t test_ubuntu_img .
[+] Building 3.4s (1/1) FINISHED                                                                                                                                  docker:default
 => [internal] load build definition from test.dockerfile                                                                                                                   1.0s
 => => transferring dockerfile: 2B                                                                                                                                          0.0s
ERROR: failed to solve: failed to read dockerfile: open test.dockerfile: no such file or directory]

그럼 저렇게 예의 그 오류가 발생합니다. 왜냐하면 snap으로 설치한 app(위의 경우 docker)은 기본적으로 사용자의 HOME 디렉터리만 접근할 수 있기 때문입니다. 따라서 저 명령어가 정상적으로 동작하려면 dockerfile을 "~" 디렉터리 하위에 옮겨서 전달하면 됩니다.

$ cd ~
$ pwd
/home/testusr

$ cp /temp/test.dockerfile ./

$ docker build -f test.dockerfile -t test_ubuntu_img .
...[생략: 정상 실행]...

snap으로 설치한 docker app의 경우 이외에도 여러 가지 제약이 있는데요, 일례로 -v 옵션을 이용한 볼륨 연결도 반드시 사용자의 홈 디렉터리 하위에 있는 경로를 지정해야 합니다.

// 이렇게 루트 하위의 /temp 디렉터리를 연결하면, /temp 디렉터리가 비어 있습니다.

$ docker run --rm -it --name test_ubuntu_inst -v /temp:/temp test_ubuntu_img /bin/bash
root@aafcdf11c29d:/# ls /temp -l
total 0

// 반면, 사용자의 홈 디렉터리 또는 그 하위에 있는 디렉터리를 연결하면 정상적으로 볼륨이 연결됩니다.

$ docker run --rm -it --name test_ubuntu_inst -v ~:/temp test_ubuntu_img /bin/bash
root@ace74a7dd225:/# ls /temp -l
total 12
drwx------ 3 1000 1000 4096 Aug 20 23:56 snap
-rw-r--r-- 1 1000 1000   33 Aug 21 01:21 test.dockerfile

참고로 사용자 디렉터리 외에도 /mnt, /media와 같은 디렉터리 역시 snap에서 접근 가능합니다.




그렇다면 허용되지 않은 경로를 app에 접근하도록 만들고 싶다면 어떻게 해야 할까요? 여러 가지 방법이 있다고 하는데, 그중에서 쉽게 쓸 수 있는 것이 바로 mount --bind를 이용해 원하는 디렉터리를 현재 사용자 디렉터리의 하위에 마운트하는 방법입니다.

가령, 위에서 예를 든 /temp 디렉터리를 접근하게 만들고 싶다면 다음과 같이 명령을 실행합니다.

$ ls /temp -l
total 4
-rw-r--r-- 1 root root 33 Aug 20 23:13 test.dockerfile

$ pwd
/home/testusr

$ mkdir temp
$ sudo mount --bind /temp ~/temp

$ ls ~/temp -l
total 4
-rw-r--r-- 1 root root 33 Aug 20 23:13 test.dockerfile

이후 저 경로를 docker 컨테이너에 연결하면 됩니다.

$ docker run --rm -it --name test_ubuntu_inst -v ~/temp:/temp test_ubuntu_img /bin/bash
root@a8bed659aba3:/# ls -l /temp
total 4
-rw-r--r-- 1 root root 33 Aug 20 23:13 test.dockerfile




일단 docker + snap 환경의 경우에 대한 문제는 이렇게 해서 해석이 되었는데, 여전히 dotnet 문제는 원인 파악이 안 됩니다. 뭐... ^^ 이렇게 조금씩 알아가다 보면 언젠가 이해될 날이 오겠죠?!!!




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







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

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

비밀번호

댓글 작성자
 




... 106  107  108  109  110  111  112  113  114  115  116  117  118  [119]  120  ...
NoWriterDateCnt.TitleFile(s)
11033정성태8/24/201625151오류 유형: 353. coreclr 빌드 시 error C3249: illegal statement or sub-expression for 'constexpr' function
11032정성태8/23/201624305개발 환경 구성: 295. 최신의 Visual C++ 컴파일러 도구를 사용하는 방법 [1]
11031정성태8/23/201620013오류 유형: 352. Error encountered while pushing to the remote repository: Response status code does not indicate success: 403 (Forbidden).
11030정성태8/23/201623968VS.NET IDE: 111. Team Explorer - 추가한 Git Remote 저장소가 Branch에 보이지 않는 경우
11029정성태8/18/201631459.NET Framework: 602. Process.Start의 cmd.exe에서 stdin만 redirect 하는 방법 [1]파일 다운로드1
11028정성태8/15/201623409오류 유형: 351. Octave 설치 시 JRE 경로 문제
11027정성태8/15/201625934.NET Framework: 601. ElementHost 컨트롤의 메모리 누수 현상
11026정성태8/13/201627190Math: 19. 행렬 연산으로 본 해밍코드
11025정성태8/12/201626351개발 환경 구성: 294. .NET Core 프로젝트에서 "Copy to Output Directory" 처리 [1]
11024정성태8/12/201625114오류 유형: 350. "nProtect GameMon" 실행 중에는 Visual Studio 디버깅이 안됩니다! [1]
11023정성태8/10/201626785개발 환경 구성: 293. Azure 구독 후 PaaS 서비스 만들어 보기
11022정성태8/10/201627512개발 환경 구성: 292. Azure Cloud Service 배포시 사용자 정의 작업을 추가하는 방법
11021정성태8/10/201624483오류 유형: 349. System.Runtime.Remoting.RemotingException - Type '..., ..., Version=..., Culture=neutral, PublicKeyToken=null' is not registered for activation [2]
11020정성태8/10/201627359VC++: 98. 원본과 대상 버퍼가 같은 경우 memcpy, wmemcpy 주의점
11019정성태8/10/201644391기타: 60. 도서: 시작하세요! C# 6.0 프로그래밍: 기본 문법부터 실전 예제까지 (2쇄 정오표)
11018정성태8/9/201628161.NET Framework: 600. 단일 메서드 내에서의 할당으로 알아보는 자바와 닷넷의 GC 차이점 [1]
11017정성태8/9/201628775웹: 33. HTTP 쿠키에 한글 값을 설정하는 방법
11016정성태8/7/201627602개발 환경 구성: 291. Windows Server Containers 소개
11015정성태8/7/201625950오류 유형: 348. Windows Server 2016 TP5에서 Windows Containers의 docker run 실행 시 encountered an error during Start failed in Win32
11014정성태8/6/201626679오류 유형: 347. Hyper-V Virtual Machine Management service Account does not have permission to open attachment
11013정성태8/6/201637619개발 환경 구성: 290. Windows 10에서 경험해 보는 Windows Containers와 docker [4]
11012정성태8/6/201627584오류 유형: 346. Windows 10에서 Windows Containers의 docker run 실행 시 encountered an error during CreateContainer failed in Win32 발생
11011정성태8/6/201628865기타: 59. outlook.live.com 메일 서비스의 아웃룩 POP3 설정하는 방법
11010정성태8/6/201625423기타: 58. Outlook에 설정한 SMTP/POP3(예:천리안 메일) 계정 암호를 잊어버린 경우
11009정성태8/3/201630752개발 환경 구성: 289. 2016-08-02부터 시작된 윈도우 10 1주년 업데이트에서 Bash Shell 사용 [8]
11008정성태8/1/201625310오류 유형: 345. 2의 30승 이상의 원소를 갖는 경우 버그가 발생하는 이진 검색(Binary Search) 코드
... 106  107  108  109  110  111  112  113  114  115  116  117  118  [119]  120  ...