0

I need to run both mosquitto and mongodb in a docker container, so I wrote this docker file

# Set the base image to Ubuntu
FROM ubuntu

RUN apt update -y && apt upgrade -y

# Install MongoDB package (.deb)
RUN apt install -y mongodb mosquitto

# Create the default data directory
RUN mkdir -p /data/db

# Expose the default port
EXPOSE 27017 1883

ENTRYPOINT mosquitto -v && mongod --bind_ip 0.0.0.0

but by doing that only mosquitto runs. If I set as entrypoint only mosquitto or only mongodb it works and I can even have access from the external, but I can't have both running in the same container. Is there a way to do that?

spike32
  • 45
  • 6

1 Answers1

2

Docker containers are designed to only run one process at a time. It can be done, but often there will be gotchas that are harder to debug. Here is another thread that discusses this idea.

Further, you'll often want to use the images provided for certain pieces of software, such as the official mongo image, and the official mosquito image. This is because they are often better optimized for exactly what they need to do.

So my advice would be to separate into two separate containers that communicate with each other.