3

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.

Neil Lunn
  • 148,042
  • 36
  • 346
  • 317
hughdbrown
  • 47,733
  • 20
  • 85
  • 108

1 Answers1

0

So the answer is that mongodb was failing to start up because I had specified a non-existent path for the data:

 "--dbpath", "/data/mongodb"

when I had created an entirely different directory earlier:

RUN mkdir -p /data/db /var/log/mongodb /var/run/mongodb
VOLUME ["/data/db", "/var/log/mongodb"]

When started with docker run -P -d, there was no output. I tried to docker run -t -i this container to see results in a terminal, but I was getting this error:

CMD = /bin/sh when using ENTRYPOINT but empty CMD

"When using entrypoint without a CMD the CMD is set to /bin/sh instead of the expected nothing."

hughdbrown
  • 47,733
  • 20
  • 85
  • 108