Mapping a Volume in a docker - mongodb

I am trying to map a Volume to the docker image using -v "/Users//data:/data/"
> docker run -p 27017:27017 --name mongo2_001 -d mongo -v "/Users/<user>/data:/data"
6cf25618d...
> docker ps -a
CONTAINER ID IMAGE COMMAND STATUS PORTS NAMES
6cf25618d.. mongo "/usr/bin/mongod -v /" Exited (1) mongoMG_001
It fails with the following error
> docker logs 6cf25618d..
2016-08-30T01:35:28.197+0000 F CONTROL [main] Failed global
initialization: BadValue: The "verbose" option string cannot
contain any characters other than "v"
When ran with out "-v ..." seems to work properly.
Not sure what could be wrong.
PS: Dockerfile used to create the image used above
FROM ubuntu:16.04
MAINTAINER Docker
RUN apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv EA312927
RUN echo "deb http://repo.mongodb.org/apt/ubuntu $(cat /etc/lsb-release | grep DISTRIB_CODENAME | cut -d= -f2)/mongodb-org/3.2 multiverse" | tee /etc/apt/sources.list.d/mongodb-org-3.2.list
RUN apt-get update && apt-get install -y mongodb-org
RUN mkdir -p /data/db
WORKDIR /data
EXPOSE 27017
ENTRYPOINT ["/usr/bin/mongod"]

The order of "-v" parameter passed was incorrect.
Instead of going to docker command "-v" options it going to mongo container. Hence reorder the command as shown below
docker run -p 27018:27017 -v /Users/<user>/data:/data --name mongo2_001 -d mongo
On windows
docker run -p 27017:27017 -v /c/Users/<user>/data:/data --name mongo2_001 -d mongo

Mike Tung answer was not working for me. I was able to make it work with following command
docker run --name mongodb_win -v mongoWinData:/data/db -d -p 37017:27017 mongo

Related

Cannot connect to MongoDB in Docker container from the host machine.

I have following image:
FROM ubuntu:16.04
RUN apt-get update
RUN apt-get install apt-transport-https -y
RUN apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 2930ADAE8CAF5059EE73BB4B58712A2291FA4AD5
RUN echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.6 multiverse" | tee /etc/apt/sources.list.d/mongodb-org-3.6.list
RUN apt-get update
RUN apt-get install -y mongodb-org=3.6.2 mongodb-org-server=3.6.2 mongodb-org-shell=3.6.2 mongodb-org-mongos=3.6.2 mongodb-org-tools=3.6.2
RUN mkdir -p /data/db
EXPOSE 27017
CMD ["--port 27017", "--smallfiles"]
ENTRYPOINT usr/bin/mongod
Run it with:
docker run --rm -ti --security-opt=seccomp:unconfined -p27017:27017 -p28017:28017 --name mong --rm mong
I see following Warning after run it:
WARNING: This server is bound to localhost.
Remote systems will be unable to connect to this server.
Start the server with --bind_ip <address> to specify which IP
addresses it should serve responses from, or with --bind_ip_all to
bind to all interfaces. If this behavior is desired, start the
server with --bind_ip 127.0.0.1 to disable this warning.
I tried to add CMD ["--bind_ip_all"] right before entrypoint but it didn't help. How to expose MongoDB to hostmachine?
Try with: --bind_ip 0.0.0.0
Your CMD becomes:
CMD ["--port 27017", "--smallfiles", "--bind_ip", "0.0.0.0"]

Install older version of MongoDB with Docker

I have this:
docker run -d --name my-name mongo
Does anyone know how to run a specific version with Docker?
something like:
docker run -d --name my-name mongo=2.4.9
I need to run mongo with version 2.4.9...
You can install any mongodb version using mongodb repo.
The Dockerfile is:
FROM ubuntu
RUN apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10
RUN echo 'deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen' | tee /etc/apt/sources.list.d/mongodb.list
RUN apt-get update
RUN apt-get install -y mongodb-10gen=2.4.9
EDIT:
You can also start mongodb container from an image with the exact version from their public docker hub repo.
Just choose the version that they have there:
curl -s https://registry.hub.docker.com/v1/repositories/mongo/tags | jq '.[] | (.name)' | awk -F'"' '{print $2}'
And start your mongodb docker container with the following command:
docker run -d --name my-name mongo:<version>
p.s. As far as we can see there are only following 2.4.x available versions of images on mongodb public docker hub repo:
2.4
2.4.10
2.4.11
2.4.12
2.4.13
2.4.14

eclipse che docker - can not create workspace - <no value>/lib/linux_amd64/terminal

I tried so set up eclipse che as described in https://eclipse.org/che/docs/setup/docker/
with the following command:
docker run -p 8080:8080 \
--name che \
--rm \
-v /var/run/docker.sock:/var/run/docker.sock \
-v /myimage \
eclipse/che-server:5.0.0-latest
che runs successfully, but during the creation of the workspace the following error message appears:
Caused by: org.eclipse.che.api.core.ServerException: Error response from docker API, status: 500, message: create <no va
lue>/lib/linux_amd64/terminal: "<no value>/lib/linux_amd64/terminal" includes invalid characters for a local volume name
, only "[a-zA-Z0-9][a-zA-Z0-9_.-]" are allowed. If you intented to pass a host directory, use absolute path
I experience this both on a debian and on a windows instance. I'm quite new to docker. What could be the cause?
I did face the same problem all through and realized that I had done my installations wrong. Following the instructions on the eclipse che website can be quite challenging if you are a newbie to it.
Kindly follow the following steps to install eclipse che using docker image and the issue you are currently facing will be gone.
(The following commands are with the assumption that you are on Debian Distribution. I am on Ubuntu 16.04)
1. Install JDK on the machine.
$ sudo apt-get update
$ sudo apt-get install default-jdk
2. Install Docker
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
$ sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
$ sudo apt-get update
$ sudo apt-get install -y docker-ce
3. Verify if docker has successfully installed
$ systemctl status docker
$ docker -v
$ sudo docker info
$ sudo docker hello-world
4. Install Eclipse CHE
$ cd ~
$ sudo mkdir eclipseche
$ sudo docker run -it --rm -v /var/run/docker.sock:/var/run/docker.sock -v ~/eclipseche:/data eclipse/che start
Docker is complaining about the syntax of this:
-v /myimage
As it's documented, they recommend to put the /data of che to a volume, in order to persist data between docker runs.
So, put this volume:
-v $(pwd)/che-data:/data
Resulting in this command:
docker run -p 8080:8080 \
--name che \
--rm \
-v /var/run/docker.sock:/var/run/docker.sock \
-v $(pwd)/che-data:/data \
eclipse/che-server:5.0.0-latest
$(pwd)/che-data is the directory in your host machine where the che's data will be saved.
/data is the directory inside che container, linked to ./che-data outside container.
-v /myimage \ is wrong :/data is correct

How to create docker image for postgis that will enable extension at build time or before container fully running?

What I mean is that I want to create a docker image for postgis that will be completely usable right after build. So that if user runs
docker run -e POSTGRES_USER=user somepostgis
the user database would be created and extensions already installed?
The official postgres image can't be used for that AFAIK.
Basically need to write script and tell that it would be entrypoint. This script should create database and create extensions with porstgres server running on different port and then restart it on port 5432.
But I don't know sh enough and docker to do that. Right now it's saying that there is no pg_ctl command
If you want to help you can fork
FROM ubuntu:15.04
#ENV RELEASE_NAME lsb_release -sc
#RUN apt-get update && apt-get install wget
#RUN echo "deb http://apt.postgresql.org/pub/repos/apt ${RELEASE_NAME}-pgdg main" >> /etc/apt/sources.list
#RUN cat /etc/apt/sources.list
#RUN wget --quiet -O - http://apt.postgresql.org/pub/repos/apt/ACCC4CF8.asc | sudo apt-key add -
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
postgresql-9.4-postgis-2.1 \
curl \
&& curl -o /usr/local/bin/gosu -SL "https://github.com/tianon/gosu/releases/download/1.2/gosu-$(dpkg --print-architecture)" \
&& curl -o /usr/local/bin/gosu.asc -SL "https://github.com/tianon/gosu/releases/download/1.2/gosu-$(dpkg --print-architecture).asc" \
&& gpg --verify /usr/local/bin/gosu.asc \
&& rm /usr/local/bin/gosu.asc \
&& chmod +x /usr/local/bin/gosu \
&& apt-get purge -y --auto-remove curl
RUN mkdir /docker-entrypoint-initdb.d
COPY docker-entrypoint.sh /
ENTRYPOINT ["/docker-entrypoint.sh"]
RUN chmod +x /docker-entrypoint.sh
RUN ls -l /docker-entrypoint.sh
EXPOSE 5432
CMD ["postgres"]
So I'm trying to do somethink like that, but it doesn't work.
#!/bin/bash
${POSTGRES_DB:=$POSTGRES_USER}
gosu postgres pg_ctl start -w -D ${PGDATA} -0 "-p 5433"
gosu postgres createuser ${POSTGRES_USER}
gosu postgres createdb ${POSTGRES_DB} -s -E UTF8
gosu postgres psql -d ${POSTGRES_DB} -c "create extension if not exists postgis;"
gosu postgres psql -d ${POSTGRES_DB} -c "create extension if not exists postgis_topology;"
pg_ctl -w restart

Docker doesn't start MONGODB, and IPAddress doesn't appear, when started with other services

I have already asked this question on serverfault.com. I am asking it here too as I see different set of questions in these 2 sites (it appears like they have different databases).
I have been trying to build an OS image from Fedora unsuccessfully to start the following:
Systemd
SSHD
RabbitMQ
MongoDB
I can get the first 3 (Systemd, SSHD and RabbitMQ-Server) to work. I can also get MongoDB to work within the container. However, I cannot get MongoDB to work along with other 3 services.
In addition, IP address doesn't show up when I try to "dockerize" MongoDB.
Am I missing something in the Dockerfile?
Here is my dockerfile:
FROM fedora:20
MAINTAINER “Ashfaque” <ashfaque#email.com>
ENV container docker
RUN yum -y update; yum clean all
RUN yum -y install systemd; yum clean all; \
(cd /lib/systemd/system/sysinit.target.wants/; for i in *; do [ $i == systemd-tmpfiles-setup.service ] || rm -f $i; done); \
rm -f /lib/systemd/system/multi-user.target.wants/*;\
rm -f /etc/systemd/system/*.wants/*;\
rm -f /lib/systemd/system/local-fs.target.wants/*; \
rm -f /lib/systemd/system/sockets.target.wants/*udev*; \
rm -f /lib/systemd/system/sockets.target.wants/*initctl*; \
rm -f /lib/systemd/system/basic.target.wants/*;\
rm -f /lib/systemd/system/anaconda.target.wants/*;
# Dockerizing SSH - is working
RUN yum -y install openssh-server
RUN yum -y install openssh-clients
RUN mkdir /var/run/sshd
RUN systemctl enable sshd.service
RUN echo 'root:mypassword' |chpasswd
EXPOSE 22
# Dockerizing RabbitMQ - is working
RUN yum -y install rabbitmq-server
EXPOSE 5672 15672
RUN systemctl enable rabbitmq-server
# Dockerizing MongoDB - is NOT WORKING
RUN yum -y install mongodb-server
RUN yum -y install boost
RUN yum -y install scons
# Create the MongoDB data directory
RUN mkdir -p /data/db /var/log/mongodb /var/run/mongodb
RUN sed -i 's/dbpath =\/var\/lib\/mongodb/dbpath =\/data\/db/' /etc/mongodb.conf
# Expose port 27017 from the container to the host
EXPOSE 27017
# Set usr/bin/mongod as the dockerized entry-point application
ENTRYPOINT ["/usr/bin/mongod"]
#CMD ["--port", "27017", "--dbpath", "/data/db", "--smallfiles", "--fork", "--syslog"]
#RUN /usr/bin/mongod --smallfiles --port 27017 --dbpath /data/db --fork --syslog
VOLUME ["/sys/fs/cgroup", "/data/db", "/var/log/mongodb", "/usr/bin"]
CMD ["/usr/sbin/init"]
Docker Commands used to build are:
(1) docker build -t rabbitmq_mongo_heisenbug .
(2) docker run --privileged -d -e 'container=docker' -v /sys/fs/cgroup:/sys/fs/cgroup:ro -p 29022:22 -p 29672:15672 -p 29017:27017 rabbitmq_mongo_heisenbug
or.. (3) docker run --privileged -ti -e 'container=docker' -v /sys/fs/cgroup:/sys/fs/cgroup:ro -p 29022:22 -p 29672:15672 -p 29017:27017 rabbitmq_mongo_heisenbug
You are using both ENTRYPOINT and CMD in your Dockerfile. This means, that docker will run /usr/bin/mongod with default parameter /usr/sbin/init. I'm pretty sure this is not what you want.
Docker will run as long as the command you specified is running. I'm not sure about /usr/bin/mongod, but if it runs in daemon mode (that is, spawn a process and return), then the container will stop running right away. The spawned processes will be terminated. The same is true for /usr/sbin/init or for any other command you specify. You can write a small shell script, which spawns the processes and runs one in the foreground, or you can use runit, or some similar tool.
Also, you probably don't need to run sshd in your container. See here why.