How can I start a service within a Docker container?

0
2
Asked By CuriousCoder92 On

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

Answered By DockerNinja34 On

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.

Answered By SysAdminChill On

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.

Answered By ContainerWhisperer21 On

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.

Answered By TechSavvyG33k On

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

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.