I'm running a Docker container using an oraclelinux image and have installed MongoDB. However, I'm facing issues trying to start the mongod service with systemctl, as it's giving me an error that the system hasn't booted with systemd as the init system. The service command is also being redirected to systemctl, which isn't working for me either. I heard about using the --privileged option, but it requires a root password that I don't have. I'm looking for a way to run a service inside a Docker container. I initially chose this approach to do some quick testing of an installation script rather than setting up a VM with oraclelinux. I understand there are ways to run MongoDB as a container, and I've created a Docker Compose file for that, but I'm mainly curious if it's feasible to start a service directly in a container.
4 Answers
Instead of trying to run MongoDB as a service, it’s better to run it in the foreground. Generally, containers are designed to run a single process, so you’d just execute the MongoDB service directly without involving systemd or any init system.
Technically, you could use a systemd image to achieve what you want but it's not recommended. Using the Docker entrypoint to directly run your process is the best practice in the Docker world.
It's not ideal to set up services like you would in a VM. Each container should run one main process. For MongoDB, consider using a dedicated MongoDB container and connect it with your application containers through Docker networks.
You might want to check Docker Hub for existing MongoDB images. They’re usually optimized for this kind of setup and can save you from having to configure everything from scratch.
Related Questions
Set Wordpress Featured Image Using Javascript
How To Fix PHP Random Being The Same
Why no WebP Support with Wordpress
Replace Wordpress Cron With Linux Cron
Customize Yoast Canonical URL Programmatically
[Centos] Delete All Files And Folders That Contain a String