Data Only Container
This is a data-only Docker image. concept in two lines. first line is for running data only container.
$ docker run --name mongo-data jaigouk/data-only-container
And second line is for running mongodb
$ docker run -p 27017 --name mongodb --volumes-from mongo-data mongodb:latest
modify dockerfile and add ssh keys
## Install an SSH of your choice. ADD your_key.pub /tmp/your_key.pub RUN cat /tmp/your_key.pub >> /root/.ssh/authorized_keys && rm -f /tmp/your_key.pub
About Docker Volume
Volumes are not for persitance.
Volumes decouple the life of the data being stored in them from the life of the container that created them. This makes it so you can docker rm my_container and your data will not be removed.
A volume can be created in two ways:
- Specifying VOLUME /some/dir in a Dockerfile
- Specying it as part of your run command as docker run -v /some/dir
Either way, these two things do exactly the same thing. It tells Docker to create a directory on the host, within the docker root path (by default /var/lib/docker), and mount it to the path you've specified (/some/dir above). When you remove the container using this volume, the volume itself continues to live on.
Basically, since volumes are not yet first-class citizens in Docker they can be difficult to manage. Most people tend to have extra volumes laying around which are not in use because they didn't get removed with the container they were used with.
Building this image
- from dockerfile
docker build -t your_name/data-only-container . and then
docker push your_name/data-only-container (assumes that you are running boot2docker locally)
- from other base image
$ docker run -i -t ubuntu /bin/bash root@215d2696e8ad:/# sudo apt-get install -y graphviz Reading package lists... Done Building dependency tree Reading state information... Done The following extra packages will be installed: ... root@215d2696e8ad:/# exit $ docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 215d2696e8ad ubuntu:14.04 /bin/bash About a minute ago Exited $ docker commit 215d2696e8ad your_name/data-only-container c5ad7718fc0e20fe4bf2c8a9bfade4db8617a25366ca5b64be2e1e8aa0de6e52 $ sudo docker push your_name/data-only-container
Using with Mongodb
run the container first
docker run --name mongodb-data your_name/data-only-container.
there is db/mongodb.conf file
port=27017 quiet=true dbpath=/data/db logpath = /data/log/mongod.log logappend=true journal=true
And in this image's dockerfile has volume.
RUN echo "copy files" COPY forever.sh /usr/local/bin/ ADD db /data/db ADD droneio /data/droneio VOLUME ["/data"]
So, you can mount this image in other mongodb image as follows.
EXPOSE 27017 EXPOSE 28017 ENTRYPOINT ["mongod", "-f", "/data/db/mongodb.conf"]
And run the mongodb image
cd docker-env-data docker build -t data . docker run -d --name data data tail -f /dev/null docker run -d -p 43153:27017 \ --name "mongo" \ --restart=always \ --volumes-from data \ jaigouk/docker-volt-mongodb