본문 바로가기

리눅스

[리눅스] docker privileged 모드로 실행

728x90

docker privileged 모드로 실행

docker(container)

docker run -d --privileged --name test7 centos:7 /sbin/init

$ docker run -d --privileged --name centos7 --hostname centos7 centos:7 /sbin/init
4a971360de73927b4b205597211b5624a7c172a476f7e1c7b6494fac73ade5e2

container 접속

$ docker exec -it centos7 bash
[root@test7 /]# systemctl list-units

docker(container) systemctl 명령 사용시 D-Bus 연결 실패 에러

$ docker run -it --rm --name centos7 centos:7 bash
[root@02e19c71bf7d /]# systemctl list-units
Failed to get D-Bus connection: Operation not permitted
$ docker run -d --privileged -v /sys/fs/cgroup:/sys/fs/cgroup:ro centos:7 /sbin/init

privileged mode 확인하기

$ docker inspect --format='{{.HostConfig.Privileged}}' centos7
true

docker-compose

github : https://github.com/anti1346/docker-privileged-mode.git

$ git clone https://github.com/anti1346/docker-privileged-mode.git

$ cd docker-privileged-mode
$ vim docker-compose.yml
version: '3.8'
services:
  centos:
    image: anti1346/centos7
    restart: unless-stopped
    hostname: centos
    container_name: centos
    privileged: true
    user: root
    working_dir: /root/
    volumes:
      - /usr/share/zoneinfo/Asia/Seoul:/etc/localtime:ro
      - /sys/fs/cgroup:/sys/fs/cgroup:ro
    command: /sbin/init
$ docker-compose up -d

privileged mode 확인하기

$ docker inspect --format='{{.HostConfig.Privileged}}' centos
true

container 접속

$ docker-compose exec centos bash
root@centos:/$

 

728x90