Answers: <p>Using <strong>systemd in Docker</strong> is not really that straightforward.  </p>
  
  <p>However, <a href="https://hub.docker.com/_/centos" rel="nofollow noreferrer">according to the doc on the docker hub</a>, <strong>systemd</strong> is now included in both the <code>centos:7</code> and <code>centos:latest</code> base containers.<br>
  However, you will need to include text similar to the example Dockerfile : </p>
  
  <pre><code>FROM centos:7
  ENV container docker
  RUN (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" ]
  CMD ["/usr/sbin/init"]
  </code></pre>
  
  <p><strong>I strongly recommend to read the full <a href="https://hub.docker.com/_/centos?tab=description" rel="nofollow noreferrer">description tab</a> documentation on the hub.</strong> This will help you make it run correctly.</p>
  
Answers: CC BY-SA 4.0
Answers: 2019-08-30T09:42:12.580Z
Answers: 2019-08-30T09:42:12.580Z
Answers: Marc ABOUCHACRA
Body: <p>Systemctl/service commands are not working on a container which is built by using centos:centos7 image.</p>
  
  <p>Can anybody help me here?</p>
  
Comments: CC BY-SA 4.0
Comments: 2019-08-26T14:11:01.273Z
Comments: Are you getting a specific error?  You may be able use a docker logs command to get the error message from the container if it isn't outputting it to the console.
Comments: Wesley Rolnick
Tags: <docker><centos>
Title: How to manage services inside the container?
UserDisplayName: deepu dileepkumar
ThreadText: # How to manage services inside the container?
  
  (Asked by: username_0 on 2019-08-26)
  
  Systemctl/service commands are not working on a container which is built by using centos:centos7 image.
  
  Can anybody help me here?
  
  **Tags:** docker, centos
  
  > **Comments:**
  > **username_1**: Are you getting a specific error?  You may be able use a docker logs command to get the error message from the container if it isn't outputting it to the console.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2019-08-30. Score: 2
  
  Using **systemd in Docker** is not really that straightforward.
  
  However, [according to the doc on the docker hub](https://hub.docker.com/_/centos), **systemd** is now included in both the `centos:7` and `centos:latest` base containers.  
  However, you will need to include text similar to the example Dockerfile :
  
  ```
  FROM centos:7
  ENV container docker
  RUN (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" ]
  CMD ["/usr/sbin/init"]
  
  ```
  
  **I strongly recommend to read the full [description tab](https://hub.docker.com/_/centos?tab=description) documentation on the hub.** This will help you make it run correctly.
  
  
  ---
  
  