카테고리 없음

chdir to cwd set in config.json failed permission denied 에러

퐁스 2020. 5. 12. 10:52

컨테이너 실행 시 루트 유저 이외의 다른 유저로 실행하였을 때 'chdir to cwd set in config.json failed permission denied' 에러가 나타났다. 이 전에 잘 되던 파일이고 chown을 통해 권한 부여도 해주었는데 계속 문제가 생겨서 이틀동안 샤워하면서도 생각하고 밥먹으면서도 생각하고 해결하기 위해 무진장 노력했다.

 문제는 소프트링크 때문이었다. 아무 생각없이 Dockerfile안에 소프트링크를 걸어주었는데, 소프트 링크의 경우 권한 변경 시 다음과 같이 변경된다.

[root@worker test]# mkdir original
[root@worker test]# ln -s original/ copy
[root@worker test]# ls -alrt
total 0
drwxr-xr-x. 5 root root 188 May 11 09:08 ..
drwxr-xr-x. 2 root root   6 May 11 09:12 original
lrwxrwxrwx. 1 root root   9 May 11 09:12 copy -> original/
drwxr-xr-x. 3 root root  34 May 11 09:12 .

이 상황에서 copy의 권한을 변경해준다.

[root@worker test]# chown -R games:games copy/
[root@worker test]# ls -alrt
total 0
drwxr-xr-x. 5 root  root  188 May 11 09:08 ..
drwxr-xr-x. 2 games games   6 May 11 09:12 original
lrwxrwxrwx. 1 root  root    9 May 11 09:12 copy -> original/
drwxr-xr-x. 3 root  root   34 May 11 09:12 .

su games를 통해 copy에 접근하면 권한 문제 없이 접근이 가능하다. 심지어 ROOT로 띄운 컨테이너에서도 된다. 그.런.데 Dockerfile에서 USER 생성문을 사용하거나 Kubernetes에서 securityContext를 주면 에러가 뜨면서 안됐다.

- Dockerfile

#open port
EXPOSE 8080

USER test
#이미지 빌드는 되지만 docker run 수행시 안됨

WORKDIR $TOMCAT_HOME/bin
CMD ["catalina.sh", "run"]

- Kubernetes yaml

securityContext:
  runAsUser: 1000
  fsGroup: 1000

이유가 뭘까... 차이점은 심볼릭링크의 여부인데 인터넷에 검색한것들이 다 안된다...!!

하나 추측하는건 이 Stackoverflow이다.

https://stackoverflow.com/questions/50812618/dockerfile-persist-symlink-in-run-instruction

 

Dockerfile: Persist symlink in RUN instruction

I am building a Docker image, and need to perform a symlink to avoid an error when later executing Python scripts. I am performing this symlink with the following command in the Dockerfile: RUN l...

stackoverflow.com

보면 볼륨이 잡혀있어야 사용할 수 있다는데 한번 해봐야겠다.