I am trying to create a Healthcheck for my MongoDB container configured in my Dockerfile:
FROM ubuntu
RUN apt-get update && apt-get install -y gnupg2
RUN apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10
RUN echo 'deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen' > tee /etc/apt/sources.list.d/mongodb.list
RUN apt-get update
RUN apt-get install -y mongodb
RUN mkdir -p /data/db
EXPOSE 27017
**HEALTHCHECK --interval=5s --timeout=3s CMD /etc/init.d/mongodb status || exit 1**
CMD ["usr/bin/mongod", "--smallfiles"]
But when I build the image and run a container, after running docker ps
it shows Up 20 seconds (unhealthy)
in the status
column.
Going into the container with bash, when I try running service mongodb start
it fails.
In the log file (/var/log/mongodb/mongodb.log
) it says Failed to set up listener: SocketException: Address already in use
But there is no other container with MongoDB running.
What could be causing this?