[Docker] Failed to get D-bus connection operation not permitted 오류 발생 시 | dasfef

2025.02.12

컨테이너 내부에서 systemctl 활용 불가할 때


도커 컨테이너 실행 후 systemctl 명령어 시행 평소와 같이 위 이미지처럼 –privileged=true 옵션과 /sbin/init 옵션을 추가했는데도 도커 컨테이너 내부에서 systemctl 을 시행하면 다음과 같은 오류가 발생한다.

Failed to get D-Bus connection


인터넷을 뒤져보던 중 이와 같은 오류를 겪는 사람이 한둘이 아니란걸 알았고 github 소스의 대단한 내용을 공유해 준 사람을 발견했다.

해결법은 다음과 같다.



해결 방법 컨테이너 내부에서 다음 명령어를 차례대로 시행한다.

mv /usr/bin/systemctl /usr/bin/systemctl.old
-- 기존 systemctl 내용을 systemctl.old로 이동

curl https://raw.githubusercontent.com/gdraheim/docker-systemctl-replacement/master/files/docker/systemctl.py > /usr/bin/systemctl
-- gdraheim 이 오픈해 둔 python 파일을 시행하여 /usr/bin/systemctl 내부에 덮어쓰기

chmod +x /usr/bin/systemctl
-- /usr/bin/systemctl 에 실행 권한 부여

위와 같이 명령어 차례대로 시행 후, 다시 systemctl을 동작시켜 보자.
이미지로 볼 수 있듯이 systemctl 명령어가 잘 먹히는 것을 확인할 수 있다.

원본 github 링크

해당 링크에서 살펴보면, docker commit을 통해 생성된 컨테이너로 이미지를 빌드하라고 하는데 본인은 이미지 빌드 시 RUN 을 통해 환경을 구성해봤다.

FROM centos:centos7.9.2009 RUN mv /usr/bin/systemctl /usr/bin/systemctl.old && curl https://raw.githubusercontent.com/gdraheim/docker-systemctl-replacement/master/files/docker/systemctl.py > /usr/bin/systemctl


CentOS 7.9 버전을 활용해 이미지를 빌드하였고, systemctl-test 라는 이름으로 빌드된 이미지로 컨테이너를 구동시켜봤다. 그리고 내부 컨테이너에서 systemctl 명령어를 시행하자 잘 실행이 되는것을 확인했다.


이전 페이지로 이동