Aravind
Aravind

Reputation: 298

systemctl command doesn't work inside docker-container

I've made a Docker image for my spring boot application. I'm unable to run systemctl command inside the Docker container. This is what I get when I execute

systemctl daemon reload :-

Failed to connect to bus: No such file or directory

Steps I followed to build the Docker image :-

1) docker build --rm -t <IMAGE_NAME> .

2) docker-compose up

3) docker exec -it <CONTAINER_NAME> bash

When I start a service using :-

service <SERVICE_NAME> start

I get unrecognised service. How do I execute a service inside docker?

Upvotes: 0

Views: 8838

Answers (2)

Guido U. Draheim
Guido U. Draheim

Reputation: 3271

If you want to reuse your existing systemd service descriptors then you either need to run systemd as the entrypoint, or you can use a wrapper script like the docker-systemctl-replacement which is both a service manager and an init daemon.

Upvotes: 2

Cameron Little
Cameron Little

Reputation: 3711

As David commented, you generally don't use process managers like systemctl in a docker environment. Instead, you can make your application the primary entry point of the image. See more in the Spring documentation about using it with docker at https://spring.io/guides/gs/spring-boot-docker/#_containerize_it.

Key is having something like this in your dockerfile, instead of systemctl daemon reload

ENTRYPOINT ["java","-jar","/app.jar"]

Upvotes: 1

Related Questions