본문 바로가기

인프라,데이터/Docker, Kubernetes

Failed to create bus connection: No such file or directory 오류 해결

환경 

  • Mac OS
  • docker for mac 4.3.2 version
  • Centos:7 이미지로 systemctl을 실행해야 되는 상황

 

보통은

centos7/systemd 이미지를 사용하거나, 

docker run --privileged --name httpd -v /sys/fs/cgroup:/sys/fs/cgroup:ro -p 80:80 -d  httpd /sbin/init

와 같이 docker run 시 --privileged 옵션을 주고 /sbin/init 을 뒤에 붙이고,

docker exec -ti httpd /bin/bash

와 같이 도커 컨테이너를 실행하면 systemctl이 실행이 되는데...

아무리 해도 Failed to create bus connection: No such file or directory 오류가 났었다;;

ps -ef | grep systemd 를 해보니 systemd 가 작동하지 않는 상황이었다.

 

계속 서칭해보니 원인은... docker for mac 버전 + centos 7 의 콤보 문제였다 ^^...

Docker Desktop now uses cgroupv2. If you need to run systemd in a container then:

docker for mac 4.3.0 버전 이상부터는 cgroupv2를 쓰기 때문에, 컨테이너 안에서 systemd를 작동시키려면 

  • centos:8 을 사용하거나
  • 컨테이너 run 시 --privileged --cgroupns=host -v /sys/fs/cgroup:/sys/fs/cgroup:rw 옵션을 주면 된다.