zivbarber
(Zivbarber)
March 4, 2017, 7:22am
1
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?
think
(Think)
March 4, 2017, 9:18am
2
yes, each RUN is a separate layer. So you cannot access from a later RUN processes from a previous RUN.
zivbarber
(Zivbarber)
March 4, 2017, 12:50pm
3
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.
friism
(Michael Friis)
March 4, 2017, 5:22pm
4
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: Volumes | Docker Docs
How it’s possible to debug a mongo image?
Use docker exec
to get a shell in an already running container.
zivbarber
(Zivbarber)
March 5, 2017, 7:57am
5
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:
Don’t use volumes.
Don’t configure any data in the docker file because it’ll be destroyed when docker run starting.
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.
think
(Think)
March 5, 2017, 11:36am
6
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.
zivbarber
(Zivbarber)
March 5, 2017, 11:39am
7
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.