I have a Dockerfile
to build mongodb on Centos 6:
# Build docker image for mongodb
FROM test
MAINTAINER ...
# Set up mongodb yum repo entry
# https://www.liquidweb.com/kb/how-to-install-mongodb-on-centos-6/
RUN echo -e "\
[mongodb]\n\
name=MongoDB Repository\n\
baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/x86_64/\n\
gpgcheck=0\n\
enabled=1\n" >> /etc/yum.repos.d/mongodb.repo
# Install mongodb
RUN yum install -y mongodb-org
# Set up directory requirements
RUN mkdir -p /data/db /var/log/mongodb /var/run/mongodb
VOLUME ["/data/db", "/var/log/mongodb"]
# Expose port 27017 from the container to the host
EXPOSE 27017
# Start mongodb
ENTRYPOINT ["/usr/bin/mongod"]
CMD ["--port", "27017", "--dbpath", "/data/mongodb", "--pidfilepath", "/var/run/mongodb/mongod.pid"]
I build it:
% docker build -t mongodb .
...
Step 8 : CMD ["--port", "27017", "--dbpath", "/data/mongodb", "--pidfilepath", "/var/run/mongodb/mongod.pid"]
---> Running in 4025f6c86f81
---> 46d71068d2e0
Removing intermediate container 4025f6c86f81
Successfully built 46d71068d2e0
I run it:
% docker run -d -P 46d71068d2e0
0bdbfd6fe86ca31c678ba45ac1328958e8126b05c717877287e725924451f7f8
I inspect it:
% docker inspect 0bdbfd6fe86ca31c678ba45ac1328958e8126b05c717877287e725924451f7f8
[{
...
"NetworkSettings": {
"Bridge": "",
"Gateway": "",
"IPAddress": "",
"IPPrefixLen": 0,
"PortMapping": null,
"Ports": null
},
I have no IPAddress.
My /etc/default/docker
has only DNS options in it:
DOCKER_OPTS="--dns 8.8.8.8 --dns 8.8.4.4"
Why? I am finding it challenging to use this without an address.
If I replace the ENTRYPOINT
and CMD
with CMD []
, I can run the container (docker run -t -i mongodb /bin/sh
) and it has an address and I can start mongod
from within the container. And it is externally accessible as a mongodb server that I can insert rows into and query.