First of all there, I know would be easier ways to solve my problem but in order to get a better understanding of docker, this is the way I want to solve running a dockerized mongodb.
I am right now trying to build my own mongodb docker image by taking a Dockerfile that's already there and modifying it. The modification: I want to be able to access a mongodb.conf file that the mongodb-server uses.
This is my Dockerfile. I only added one line VOLUME ["/etc"]
and I changed the last line (I added the last -f
parameter). Building the image and running it in a container worked fine without those changes.
FROM debian:jessie-slim
RUN apt-get update && \
apt-get install -y ca-certificates && \
rm -rf /var/lib/apt/lists/*
RUN gpg --keyserver ha.pool.sks-keyservers.net --recv-keys 0C49F3730359A14518585931BC711F9BA15703C6 && \
gpg --export $GPG_KEYS > /etc/apt/trusted.gpg.d/mongodb.gpg
ARG MONGO_PACKAGE=mongodb-org
ARG MONGO_REPO=repo.mongodb.org
ENV MONGO_PACKAGE=${MONGO_PACKAGE} MONGO_REPO=${MONGO_REPO}
ENV MONGO_MAJOR 3.4
ENV MONGO_VERSION 3.4.18
RUN echo "deb http://$MONGO_REPO/apt/debian jessie/${MONGO_PACKAGE%-unstable}/$MONGO_MAJOR main" | tee "/etc/apt/sources.list.d/${MONGO_PACKAGE%-unstable}.list"
RUN echo "/etc/apt/sources.list.d/${MONGO_PACKAGE%-unstable}.list"
RUN apt-get update
RUN apt-get install -y ${MONGO_PACKAGE}=$MONGO_VERSION
VOLUME ["/data/db"]
VOLUME ["/etc"]
WORKDIR /data
EXPOSE 27017
CMD ["mongod", "--smallfiles", "-f /etc/mongodb.conf"]
With my changes however, the builded image can not start. It immediately exits. docker logs <container-name>
gives me
Error reading config file: No such file or directory
try 'mongod --help' for more information
I used the run command
docker run -p 37017:27017 -d -v /tmp/mongodb/data:/data/db -v /tmp/mongodb/etc:/etc mongo-image
and expected that the file located at /tmp/mongodb/etc/mongodb.conf on my host-system would be found then (yes, it exists there, I placed it there).
What am I doing wrong? I am new to docker and I think I messed up the volumes maybe?