Start service using systemctl inside docker conatiner

In my Dockerfile I am trying to install multiple services and want to have them all start up automatically when I launch the container. One among the services is mysql and when I launch the container I don’t see the mysql service starting up. When I try to start manually, I get the error: Failed to get D-Bus connection: Operation not permitted


FROM centos:7

RUN yum -y install mariadb mariadb-server

CMD ["/bin/bash", “service mariadb start”]

Docker build:
docker build --tag=“pbellamk/mariadb” .

Docker run:
docker run -it -d --privileged=true pbellamk/mariadb bash

I have checked the centos:systemd image and that doesn’t help too. How do I launch the container with the services

Can someone show an example of how to start the container with 3 services(mariadb, httpd, sshd) to be running when it is launched ?

started using systemctl/service commands. has an example (somewhat Python oriented) of running an application with separate containers for a database (in their example, PostgreSQL) and an application, with one process per container. You should follow this pattern.

You can’t run systemd in a container without giving it unrestricted access to the host system. I’d avoid it if at all possible. (As a corollary, commands like systemctl or service or things that start processes in the background generally don’t work in the Docker environment.) Similarly, running sshd in a container is tricky and generally unnecessary (it raises many questions around host keys, and port mappings, and not leaking credentials in Docker images) and I’d avoid it.