Docker + mongodb + run mongo to setup the db

I made a docker file for mongodb.
I used:

Centos 7
Mongodb 2.6.12
my configuration file

I used other port for the db instead of 27017

It took me time to find out how to access it but at the end I found out that this is working from my host machine:

mongo --port 35350

At the end of the docker file I have:

ENTRYPOINT ["/usr/bin/mongod","–auth","–config","/etc/mongod.conf"]

The problem is that when setting up the mongodb image I want to run some mongo commands.
I tried to add this into my docker file:

RUN /usr/bin/mongod --fork --noauth --config /etc/mongod.conf
RUN mongo mydb --port 35350 --eval ‘…’

I got connection refuse

hmmm… maybe docker close everything on each RUN?
so I tried putiing it on .sh file and execute it with RUN - same thing.

What I’m doing wrong?

yes, each RUN is a separate layer. So you cannot access from a later RUN processes from a previous RUN.

Arrr…
It was my problem.
But anyway something not working for me.
To make it easy for me I need to know some basic things:

What are images?
As I understand it, they are like the VM description+disks that you running.

Where are images been stored in my computer?
I tried to locate them without any luck.

What about the data stored inside the images disks?
Is it cleared when I build a new version of the image?

How it’s possible to debug a mongo image?
Or, how can I run both the normal mode that running mongod and bash? on the SAME image disks.

Where are images been stored in my computer?

With Docker for Windows, they’re stored in the VM image that powers Linux containers.You can list images with docker images. Why do you want to know where on the computer they’re stored?

What about the data stored inside the images disks?
Is it cleared when I build a new version of the image?

images are separate from running or stopped containers. To keep data around for containers, use volumes: https://docs.docker.com/engine/tutorials/dockervolumes/

How it’s possible to debug a mongo image?

Use docker exec to get a shell in an already running container.

Thanks for your reply.
While the -v for docker run not working I managed to add this to the dockerfile:

VOLUME ["/var/lib/mongo"]

While I can see the volume in inspect, every time that I run my container it ease everything inside the volume.

Update:

At the end the only way to make it to work is:

  1. Don’t use volumes.
  2. Don’t configure any data in the docker file because it’ll be destroyed when docker run starting.
  3. So I made some shell scripts to run on docker run to add all the data.

Now it’s working but a need to find a way to backup the data in the container:

Maybe a schedule a task to docker exec a backup on the database and then docker cp the result to some remote server?

It still stupid but… docker is so limited.

Anyway, my next task to find out how another docker can connect to the db from remote.

If you want to backup a volume you could consider to use tools specialized for this.
e.g.: https://github.com/ClusterHQ/dvol/

I think a great advantage of docker is, that you can make it work and after that make it nice.
This basically means first you have your bunch of bashfiles to make it somehow working. After that you replace them file by file with some established solutions like dvol for example.

Thanks.
I managed to use the volume command:

It turned out that you must put the volume command at the end just before the entry point.
Now my first docker is almost working as I want to.