title: Unable to run systemd inside docker which is being run inside jenkins
body: <p><strong>I'm trying to get Jenkins to run Docker that runs SystemD</strong>.</p>
  
  <p>So far <strong>I've been able to run systemd inside docker locally without Jenkins</strong>. Here are the steps to run it locally without jenkins:</p>
  
  <pre><code># pull unop/fedora-systemd and create and run the container for it
  sudo docker run --cap-add=SYS_ADMIN -e container=docker --tmpfs /run --tmpfs /tmp -v /sys/fs/cgroup:/sys/fs/cgroup:ro -t -i unop/fedora-systemd
  
  # on a different terminal window, I can:
  # get the container id of the "unop/fedora-systemd" image
  sudo docker ps
  
  # then exec bash on it
  sudo docker container exec -t -i a98aa2bcd19e bash # where a98aa2bcd19e is the container id found above
  
  # once inside the container, I can run systemd without any problems. examples:
  systemctl status
  systemctl start dbus.service
  systemctl status dbus.service
  </code></pre>
  
  <p>The above works locally and I am able to run systemd inside the docker container.
  The problem I get is when I try the same thing, but inside Jenkins.</p>
  
  <p>I've tried to tweak Jenkinsfile several times, but not of my previous tries seemed to work. I always get an <strong>error when running under Jenkins</strong> similar to this: </p>
  
  <pre><code>+ systemctl status
  System has not been booted with systemd as init system (PID 1). Can't operate.
  Failed to connect to bus: Host is down
  </code></pre>
  
  <p>This is my latest <strong>Jenkinsfile</strong> that I've tried</p>
  
  <pre><code>pipeline {
      agent {
          docker {
              image 'unop/fedora-systemd'
              args '--cap-add=SYS_ADMIN -e container=docker --tmpfs /run --tmpfs /tmp -v /sys/fs/cgroup:/sys/fs/cgroup:ro -t -i'
          }
      }
  
      stages {
          stage('test') {
              steps {
                  sh "echo hello world"
                  sh "systemctl status"
                  sh "systemctl start dbus.service"
                  sh "systemctl dbus.service"
              }
          }
      }
  }
  </code></pre>
  
  <p>On previous iterations of the Jenkinsfile, I've tried to replace <code>-cap-add=SYS_ADMIN -e container=docker</code> for <code>--privileged</code>, but that didn't help, I still got the same errors</p>
  
  <p><strong>Anyone have an idea of how can I get this to work? Why does the above work locally, but not on Jenkins? what am I missing here?</strong></p>
  
  <p>Note: Jenkins version: 2.150.2 and this is the <strong>Dockerfile</strong> used by <em>unop/fedora-systemd</em></p>
  
  <pre><code>FROM fedora:rawhide
  MAINTAINER http://fedoraproject.org/wiki/Cloud
  
  ENV container docker
  
  RUN dnf -y update &amp;&amp; dnf clean all
  
  RUN dnf -y install systemd &amp;&amp; dnf clean all &amp;&amp; \
  (cd /lib/systemd/system/sysinit.target.wants/; for i in *; do [ $i == systemd-tmpfiles-setup.service ] || rm -f $i; done); \
  rm -f /lib/systemd/system/multi-user.target.wants/*;\
  rm -f /etc/systemd/system/*.wants/*;\
  rm -f /lib/systemd/system/local-fs.target.wants/*; \
  rm -f /lib/systemd/system/sockets.target.wants/*udev*; \
  rm -f /lib/systemd/system/sockets.target.wants/*initctl*; \
  rm -f /lib/systemd/system/basic.target.wants/*;\
  rm -f /lib/systemd/system/anaconda.target.wants/*;
  
  VOLUME [ "/sys/fs/cgroup", "/tmp", "/run" ]
  CMD ["/usr/sbin/init"]
  </code></pre>
  
  <p>PS: I've seen a <a href="https://stackoverflow.com/questions/40053483/how-to-enable-systemd-service-in-openshift-jenkins-1-centos7-docker-container">related question</a>, but what they were asking is different</p>