简体   繁体   中英

How to run privileged Docker container for using systemctl

I am new to Docker and I am trying to use systemctl to restart a service. It constantly fails and Failed to get D-Bus connection: Operation not permitted . I understand that in order to bypass this I need to run a privileged docker container, however, this still does not produce my desired results.

Please see below for the steps I took and the files involved:

Docker command result

docker run --privileged testapp /sbin/init

Dockerfile

FROM openjdk:14.0.1

# Copies required files to the Linux container
COPY ./out/production/TestingApp/ /App
COPY test.sh /App
COPY expressvpn-2.5.1.1-1.x86_64.rpm /App

WORKDIR /App

RUN yum -y update
RUN yum -y install sudo && yum -y install expect && yum -y install systemd
RUN yum -y install expressvpn-2.5.1.1-1.x86_64.rpm

ENTRYPOINT ["java", "Main"]

test.sh

In my Main.java this shell script file is executed and the output is printed out to the console.
 sudo systemctl start expressvpn.service expressvpn status

try

docker run -u 0 testapp /sbin/init

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM