Programming/Docker
[Docker] 컨테이너에서 sudo 사용하기
★용호★
2017. 4. 25. 20:26
sudo 명령을 실행하기 위해서는 sudo 설치 및 사용자 설정이 필요하다. 아래 절차를 Dockerfile의 RUN 명령문에 지정하면 된다.
1. sudo 설치
$ apt-get update && apt-get install -y sudo
2. 사용자 계정 추가 (아래 명령에서 사용자명은 user이다.)
$ adduser --disabled-password --gecos "" user \
&& echo 'user:user' | chpasswd \
&& adduser user sudo \
&& echo 'user ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers
이 때 sudoers에 추가한 유저에 대한 설정을 하지 않으면 sudo를 사용할 수 없다. /etc/sudoers의 내용을 보면 %sudo로 시작하는 설정이 있는데 이는 sudo group에 속한 유저에 대한 권한 설정이다.
NOPASSWD 설정을 해주지 않으면 sudo 그룹에 속한 유저라도 아래와 같이 최초 한번 비밀번호를 물어보게 되므로 Dockerfile 빌드 시 에러가 난다.
We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these three things:
#1) Respect the privacy of others.
#2) Think before you type.
#3) With great power comes great responsibility.
sudo: no tty present and no askpass program specified