Mongodb-org-server.postinst: systemctl: not found

I am following the directions here:

I am attempting to create a docker image based on the openjdk image and wish to install a mongdb server there, which I’m using internally to manage temporary databases.

I wanted to make sure what I was running, so I ran cat /etc/os-release in my image, and it displayed the following data:

NAME="Debian GNU/Linux"
VERSION="10 (buster)"

When I get to the command apt-get install -y mongodb-org I get the following error

/var/lib/dpkg/info/mongodb-org-server.postinst: 43: /var/lib/dpkg/info/mongodb-org-server.postinst: systemctl: not found
dpkg: error processing package mongodb-org-server (--configure):
 installed mongodb-org-server package post-installation script subprocess returned error exit status 127

I searched for the error, including this forum, and couldn’t find it, so I’m posting here. Please advise.


Hi @Thom_Hehl and welcome in the MongoDB Community :muscle: !

Usually Docker images are as small as possible so most of the time, they only embed what is absolutely necessary for them to work.

systemctl is not part of the OpenJDK image you are trying to use apparently (makes sense to me) which is required for MongoDB installed by the package manager because it would configure MongoDB to start automatically when your computer starts, etc. Which doesn’t make sense in a Docker container.

So a few advises:

  • it’s weird to install MongoDB in another existing image. The entire philosophy of Docker is to keep things separated and clean. You are doing the exact opposite here.
  • You probably want to run your Java program and communicate with MongoDB. I would do this by connecting the docker containers together with docker network or with docker-compose.
  • There is already a MongoDB image available.
  • If you are still up to the challenge, I would definitely use the MongoDB tarball instead of the package manager to install the MongoDB binaries. But I would use the package manager for the dependencies.


1 Like

There are perfectly valid reasons for installing the MongoDB packages in a container environment. For instance, we use Gitlab pipelines (which run in docker containers) for testing, where the test runner expects to find a mongod executable. So far, we could provide the binary by installing the Debian/Ubuntu packages. This is not possible now with the hard requirement on systemd.

Hi @languitar,

When you install MongoDB a the packet manager, you are installing it as a service on your machine which will start during the boot. It’s hard to do that without systemd / systemctl and it’s not what you want in a docker container - indeed.

If you just want to install MongoDB binaries without all the service configurations, use the tarball like this one for MDB 4.4.2 for Ubuntu 20.04:

You can find all these links in the MongoDB Download Center right next to the download button once you have selected what you need.


But why can’t it just install itself including the systemd service files but without registering? Many other packages do that as well.

As a side note: a dependency is probably missing here then, because the missing systemd is not caught via package dependencies.

The official container installs by linking /bin/true to /usr/local/bin/systemctl and removes it after installing mongodb-org-* packages.


this post and workaround method deserves more than a hundred upvotes.

IMHO we can not assume systemctl always present.

1 Like

This worked for me in a debian 10 container: ln -T /bin/true /usr/bin/systemctl && apt-get update && apt-get install -y mongodb-org && rm /usr/bin/systemctl

1 Like

This solution fixed my problem.
@Edward_Bordin posted an example code on how to fix the two comments below.

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.