I try to run a Seyren instance locally, and I would like to do it using the dockerized MongoDB image.
After I pulled the latest docker image, I run it and expose the 27017 port:
docker run --name mongodb -v /data/db:/data/db -p 27017:27017 -d mongo
Next thing to do is compile the seyren jar file and passing it some variables. docker.local is mapped to the IP of the docker toolbox in /etc/hosts
java -jar seyren-1.3.0.jar GRAPHITE_URL=https://graphiteurl.io MONGO_URL=mongodb://docker.local:27017
But I then got the following errors:
30/03/2016 13:58:02.643 [localhost-startStop-1]
INFO com.seyren.mongo.MongoStore - Ensuring that we have all the indices we need 30/03/2016 13:58:12.661 [localhost-startStop-1]
ERROR
com.seyren.mongo.MongoStore - Failure while bootstrapping Mongo
indexes. If you've hit this problem it's possible that you have two
checks which are named the same and violate an index which we've tried
to add. Please correct the problem by removing the clash. If it's
something else, please let us know on Github!
com.mongodb.MongoTimeoutException: Timed out after 10000 ms while
waiting for a server that matches AnyServerSelector{}. Client view of
cluster state is {type=Unknown, servers=[{address=localhost:27017,
type=Unknown, state=Connecting,
exception={com.mongodb.MongoException$Network: Exception opening the
socket}, caused by {java.net.ConnectException: Connection refused}}]
What do I do I miss here?
EDIT:
The thing when I compile the seyren jar file. I indeed have a seyren database which is created in my mongo instance ... So there must be a connection established.
As I understood you are using docker toolbox on Mac. Docker toolbox is running not in your localhost (it's running in instance of VBox virtual machine). And you should to use the IP of this machine instead of localhost. You can get it using docker-machine env command in terminal. IP of DOCKER_HOST env variable will be the IP of your mongoDB instance host.
Found the solution. I had to use mongo:2.7 image since this is the only workable one.
Related
I am using the jupyter/scipy-notebook image and want to connect to a MongoDB that runs locally on MacOS (port-forwarded through K8). I cannot get this to work. I can connect from the docker to the host using "host.docker.internal" but cannot reach MongoDB.
I tried two different approaches
A. Using the network flag to avoid the issue entirely:
docker run --network="host" jupyter/scipy-notebook:b418b67c225b
Result: Cannot reach the notebook at all on localhost:8888
B. Running the image without the network flag and connect to "host.docker.internal" when using the MongoDB.
docker run -p 8888:8888 jupyter/scipy-notebook:b418b67c225b
client = MongoClient("mongodb://host.docker.internal:27017/?readPreference=primary&ssl=false")
db = client["foo"]
db.list_collection_names()
Result: Some kind of topology error:
ServerSelectionTimeoutError: Could not reach any servers in ........ [Errno -3] Temporary failure in name resolution')>]>
Any ideas?
I'm working on a very basic (I thought) starter program in Go using MongoDB and Docker. Trying to get a handle on these before we start using them at work.
I've got my MongoDB running in a docker container, just using my local host, using the official Docker image. This is running fine, I can connect to it through MongoDB Compass and modify the DB.
My next task was to build a separate Docker container that is able to read and write to the DB. I'm using MongoDB-Go-Driver (https://godoc.org/github.com/mongodb/mongo-go-driver/mongo) for this as mgo is no longer kept up.
This is my code, I'm just following the numerous tutorials online to make a simple connection and then ping the DB to ensure connectivity.
client, err := mongo.Connect("mongodb://localhost:27017")
if err != nil {
log.Fatal("error ", err)
}
// Check the connection
err = client.Ping(context.TODO(), nil)
if err != nil {
log.Fatal("error2 ", err)
}
fmt.Println("Connected to MongoDB!")
It always fails on doing any operation on the DB (Find, FindOne, Ping, etc.) with error2 server selection timeout
This is my docker-compose file I'm running.
version: "3"
services:
datastore:
image: mongo
ports:
- "27017:27017"
networks:
- maccaptionNet
volumes:
- .:/go/src/maccaption_microservice/dbdata
jobservice:
image: jobservicemaccaption:1.0
networks:
- maccaptionNet
depends_on:
- "datastore"
networks:
maccaptionNet:
driver: bridge
I'm brand new to MongoDB and after hours of research haven't made any progress on this.
I've read through https://docs.mongodb.com/manual/core/read-preference-mechanics/
https://docs.mongodb.com/manual/replication/
Can anyone point me in the right direction for this? I haven't been able to find a lot on this specific issue.
Thanks!
When you running the service and mongodb in docker you can't use localhost since the service is in a different container than mongodb, and from docker point of view it's under a different ip address.
You can connect with the service name you specify in docker-compose datastore
mongo.Connect("mongodb://datastore:27017")
Edit:
from: https://docs.docker.com/compose/networking/
By default Compose sets up a single network for your app. Each
container for a service joins the default network and is both
reachable by other containers on that network, and discoverable by
them at a hostname identical to the container name
Meaning that if you run multiple containers via compose, you can access one container from the other by the container name,
Basically when docker-compose starts, it sets up the network, and each container in the compose joins the network under its container name. For a container's point if view, localhost is just the container itself, while he can search for other container's name and get back the container’s IP address.
Assuming that the docker is running on your localhost, you can set the name in etc/hosts file like this:
127.0.0.1 datastore
(if not just replace 127.0.0.1 with the docker ip)
And in the app you will connect with mongodb://datastore:27017
So you will be able to run the service both in the docker and from outside, if you'll decide to run only the db in docker
docker-compose start datastore
If you are connecting to one docker from another (like it is written in your docker-compose file, and using bridge network mode, you have to change your localhost to the hostname, like datastore
client, err := mongo.Connect("mongodb://datastore:27017")
When your go script uses localhost, it expects the database to located in the same docker
I think my answer might be unrelated but still, I was getting the same error and it was because my IP address was not listed in the IP whitelist tab in MongoDB atlas, so make sure you have your IP address there before trying to connect.
I had the same problem but found another way to address this issue. You can just pass network parameter while running docker image and this way docker points to correct localhost.
docker run --network="host" ....
Source for this solution
Somehow i've fix this problem in a different way: by changing ports from "27018:27017" to "27017:27017".
IDK why this helps. Maybe if Mongo sees not default port it thinks there are cluster of Mongo's nodes.
I got this problem when I tired to connect to
mongodb v4.0.10
with
pymongo==4.0.2 not worked
pymongo==3.12.3 worked
Check your packages
mongodb v5.0.2 works with pymongo==4.0.2
I have created a docker container image on my Bluemix private registry. My docker image (Dockerfile) contains the following things-
FROM registry.ng.bluemix.net/ibmliberty
RUN rm -rf /opt/ibm/wlp/usr/servers/defaultServer/server.xml
ADD server.xml /opt/ibm/wlp/usr/servers/defaultServer/server.xml
RUN rm -rf /opt/ibm/wlp/usr/servers/defaultServer/workarea
ADD ./build/libs/*.war /opt/ibm/wlp/usr/servers/defaultServer/apps
ENV LISCENSE accept
I also created a mongoDB service to attach with my container.
When I am done with creating my container and binding it with the mongoDB service, then I hit containers (IP/URL). My application is running but not connecting to the database. In container logs I am getting socketTimeout exception.
logs-
0[err] at java.lang.Thread.run(Thread.java:785)
[err] com.mongodb.MongoTimeoutException: Timed out after 30000 ms while waiting
for a server that matches ReadPreferenceServerSelector{readPreference=primary}.
Client view of cluster state is {type=UNKNOWN, servers=[{address=50.23.230.160:1
0082, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketOpenExce
ption: Exception opening socket}, caused by {java.net.SocketTimeoutException: co
nnect timed out}}]
I have included the db parameter in my server.xml, and also tried different approaches to give the db parameter while creating the container by specifying Environment variable. These parameters contain almost all information like host,port,db,uname,pwd.
After trying lots of approaches in different ways, I am not able to find what I am doing wrong. Please help me to resolve this issue.
I am using docker-compose to run Orion+Mongo.
Then, I am starting accumulator-server with:
drasko#Lenin:~/fiware/fiware-orion/scripts$ ./accumulator-server.py 1028 /accumulate on
verbose mode is on
* Running on http://0.0.0.0:1028/ (Press CTRL+C to quit)
However, running a gives an error:
orion_1 | WARNING#21:27:21 httpRequestSend.cpp[438]: Notification failure for localhost:1028 (curl_easy_perform failed: Couldn't connect to server)
Could it be due the fact that Orion is run in the Docker and how to solve this problem?
Your problem is that your Orion host cannot reach the accumulator.
In the subscription you are using a reference field with the value "localhost", so Orion is looking in its localhost relative to the docker container.
To solve it, you should either run the accumulator inside the docker image or make Orion able to contact the accumulator in some other way than "localhost" (maybe run accumulator in a different container and link it using docker compose).
I have installed mongodb on a docker container together with openssh on ubuntu 14.04. The container is running with ssh but when I ssh into the container I get the following error when trying to start mongod.
root#430f9502ba2d:~# service mongod start
Rather than invoking init scripts through /etc/init.d, use the service(8)
utility, e.g. service mongod start
Since the script you are attempting to invoke has been converted to an
Upstart job, you may also use the start(8) utility, e.g. start mongod
Also start mongod does not affect anything.
Tried looking at this also Mongo daemon doesn't run by service mongod start without it helping.
mongod --config /your/path/to/mongod.conf doesn't seem to work also, just locks up.
The error below is standard as of course there is no mongod server running.
root#430f9502ba2d:/# mongo
MongoDB shell version: 2.6.9
connecting to: test
2015-05-07T20:49:56.213+0000 warning: Failed to connect to 127.0.0.1:27017, reason: errno:111 Connection refused
2015-05-07T20:49:56.214+0000 Error: couldn't connect to server 127.0.0.1:27017 (127.0.0.1), connection attempt failed at src/mongo/shell/mongo.js:146
exception: connect failed
The problem here is your approach. Docker does not have an init system like you are used to on traditional systems. What docker does is replace PID 1 with the process you specify in the CMD or ENTRYPOINT Dockerfile commands. For now, ignore ENTRYPOINT, because it replaces what your CMD is run with (normally, it's /bin/sh -c). You need to instruct docker to start your mongod service in your Dockerfile with the CMD command, like:
CMD usr/bin/mongod
And when you run your container, mongod will be your PID 1. Now, you're probably wondering at this point "But what about my SSH server?" and the answer is: Don't run an SSH server on your docker containers. There are some use cases where running an SSH server is okay, but almost all of the "normal" reasons (debug, C&C, etc) are nullified with the "best practice" for getting a shell on your container:
docker exec -it myContainer /bin/bash
This will drop you into a shell on your running container. The recommendation here for managing configuration and changes in your docker container is to use something like Ansible. However, remember that docker containers are ephemeral, and you shouldn't be restarting services and changing configuration state on them. If you need a config change, change the Dockerfile or config data, and then start a new container. Good luck! Here is a little more information on Dockerizing MongoDB, but keep in mind that the method described there alters the ENTRYPOINT in the Dockerfile, which is a little more involved and requires a better understanding of what's going on in Dockerfiles.
This is really helpful. I was trying to make old Ansible playbooks work with Docker by creating several blank containers and let Ansible do the rest.
It works through command
mongod --dbpath /var/lib/mongodb --smallfiles