I have a problem and when I run mongo db with docker or without docker I get that error
this is my command
docker run -d --net="host" --name mongo -v /etc/mongod.conf:/etc/mongod.conf mongo -f /etc/mongod.conf
this is my /etc/mongod.conf
storage:
dbPath: /var/lib/mongodb
journal:
enabled: true
systemLog:
destination: file
logAppend: true
path: /var/log/mongodb/mongod.log
port: 27017
security:
authorization: enabled
mongodb logs
2019-08-13T06:44:50.454+0000 I STORAGE [main] Max cache overflow file size custom option:** 0 </p>
sudo chown -R {username} /data
make the folder in mongodb dbpath have file write permission
I was having this problem too, and after some investigation, my coworkers found that this seems to be a problem with v4.0.12. If you force it to use v4.0.11 or something, then it appears to work. For example, I'm setting up MongoDB via Ansible, and in my configuration playbook, I have something like this to dictate the version used for my mongoDB packages:
- name: Update repositories cache and install our mongodb packages
apt:
name: "{{ packages }}"
update_cache: yes
vars:
packages:
- mongodb-org=4.0.11
- mongodb-org-server=4.0.11
- mongodb-org-shell=4.0.11
- mongodb-org-mongos=4.0.11
- mongodb-org-tools=4.0.11
- numactl
- python-pip
become: true
I've seen this log message caused by Mongod attempting to write to a full partition. This was because mongo_global.log grew to 13 GB, all of the available space.
Related
I'm trying to use my local mongodb inside my docker container.
To allow access, I have edited my mongo.conf as follows:
but when running mongo db restart, I get this in the mongodb.log:
systemLog:
destination: file
path: /opt/homebrew/var/log/mongodb/mongo.log
logAppend: true
storage:
dbPath: /opt/homebrew/var/mongodb
net:
bindIp: 127.0.0.1,172.17.0.1
ipv6: false
Can't assign requested address
{"t":{"$date":"2022-09-21T15:35:17.125+03:00"},"s":"E", "c":"CONTROL", "id":20568, "ctx":"initandlisten","msg":"Error setting up listener","attr":{"error":{"code":9001,"codeName":"SocketException","errmsg":"Can't assign requested address"}}}
and running brew services restart mongodb-community && brew services list
mongodb-community error 12288 ~/Library/LaunchAgents/homebrew.mxcl.mongodb-community.plist
I am trying simply to use mongo with custom configuration file placed in my host machine. I obtain 100 error code, I tested this in debian 10 and on a windows 10 machine (docker desktop). I think that its a permission issue, may be mongo has not permission to use those files.
docker-compose.yml
version: "3.7"
services:
mongod:
image: mongo:4.1.13
# restart: always
ports:
- "27017:27017"
volumes:
- ./config/mongo/mongod.conf:/etc/mongod.conf
- ./data/mongo:/data/db
# - ./log/mongo:/var/log/mongodb
entrypoint: ["mongod","--config","/etc/mongod.conf","--verbose"]
mongod.conf (default)
# mongod.conf
# for documentation of all options, see:
# http://docs.mongodb.org/manual/reference/configuration-options/
# Where and how to store data.
storage:
dbPath: /var/lib/mongodb
journal:
enabled: true
# engine:
# mmapv1:
# wiredTiger:
# where to write logging data.
systemLog:
destination: file
logAppend: true
path: /var/log/mongodb/mongod.log
# network interfaces
net:
port: 27017
bindIp: 127.0.0.1
# how the process runs
processManagement:
timeZoneInfo: /usr/share/zoneinfo
#security:
#operationProfiling:
#replication:
#sharding:
## Enterprise-Only Options:
#auditLog:
#snmp:
Error:
This, this image does not create a log file under /var/log/mongodb.
Your docker-compose.yml and mongod.conf has inconsistent options:
docker-compose.yml specifies /data/db as a folder for DB files, but mongod.conf tries to use dbPath: /var/lib/mongodb (which is missing in your container). Fix your mongod.conf to point to /data/db/ folder and it should fix your error.
To debug such kind of error, your can run your image (mongo) by hand (docker run ...) with bash, instead of using docker-compose and you will be able to see all error in logs.
I'm setting a mongodb container using docker, and persisting data and logs in volumes mapped into the host. The main idea is to up a mongodb container persisting the data.
But the problem, is that I want to create a mongodb admin user and database user (with less permissions) during the startup of the container and if the container is restarted the users won't need to be created again once the data is persisted.
With respect to the creation of the mongodb container, I found many answers in the stackoverflow and I created a Dockerfile, docker-compose.yml and mongodb.conf. It worked fine.
But I didn't find a clear solution related to the creation of users. There are some javascript codes that can be used to create users in mongodb during the initialization of the containers. But it is not clear what happens (or must be happened) with the scripts after the users were created when the container is restarted so to avoid the container to create the users again.
Dockerfile
FROM ubuntu:latest
RUN apt-get update && \
apt-get install -qq -y curl wget gnupg gnupg2
RUN wget -qO - https://www.mongodb.org/static/pgp/server-4.2.asc |
apt-key add -
RUN echo "deb [ arch=amd64 ] https://repo.mongodb.org/apt/ubuntu
bionic/mongodb-org/4.2 multiverse" | tee
/etc/apt/sources.list.d/mongodb-org-4.2.list
RUN apt-get update && \
apt-get install -y mongodb-org && \
apt-get autoclean && \
apt-get clean
ADD mongodb.conf /etc/mongodb.conf
ENTRYPOINT ["/usr/bin/mongod", "--config", "/etc/mongodb.conf"]
CMD ["--quiet"]
docker-compose.yml
version: '3'
services:
mongo:
build: .
container_name: mongodb
image: mongodb_img
environment:
- MONGODB_USER="${MONGODB_USER}"
- MONGODB_PASS="${MONGODB_PASS}"
- MONGODB_DB="${MONGODB_DB}"
- MONGODB_ADMIN="${MONGODB_ADMIN}"
- MONGODB_ADMIN_PASS="${MONGODB_ADMIN_PASS}"
ports:
- 27017:27017
volumes:
- /data/db/:/var/lib/mongodb/
- /data/logs/:/var/log/mongodb/
Currently, it starts the mongodb container without users and without authentication mapping the data and logs, respectively, into the volumes /data/db and /data/logs.
I want that the container starts with an admin user, a specific database, database user and authentication.
If the container restarts the users and database won't need to be created since the data is persisted.
I did some modifications in the docker-compose.yml and mongodb.conf files, and I made two scripts to create admin and database users. For now, it is working as I expected.
I hope that it can be useful to others and if someone has a different solution be glad to share with us.
docker-compose.yml
version: '3'
services:
mongo:
build: .
container_name: mongodb
image: mongodb_img
ports:
- 27017:27017
command: --auth
volumes:
- /data/db/:/var/lib/mongodb/
- /data/logs/:/var/log/mongodb/
- /data/setup/:/setup
mongodb.conf
# mongod.conf
# for documentation of all options, see:
# http://docs.mongodb.org/manual/reference/configuration-options/
# Where and how to store data.
storage:
dbPath: /var/lib/mongodb
journal:
enabled: true
# where to write logging data.
systemLog:
destination: file
logAppend: true
path: /var/log/mongodb/mongod.log
# network interfaces
net:
port: 27017
bindIp: 0.0.0.0
security:
authorization: "enabled"
setup/create-user.js
db.createUser({
user: "db_username",
pwd: "db_user_password",
roles: [
{role: "readWrite", db:"db_name"}
]
})
setup/create-admin.js
db.createUser({
user: "admin_user",
pwd: "admin_password",
roles: [
{role: "userAdminAnyDatabase", db: "admin"},
{role: "readWrite", db:"admin"}
]
});
In order to initialize the container I used the command:
docker-compose up -d --build
So to create the users run the following commands:
docker exec mongodb mongo admin ./setup/create-admin.js
and
docker exec mongodb mongo db_name ./setup/create-user.js -u admin_user -p admin_password --authenticationDatabase admin
I have several docker containers , one of them is Mongodb official image,
Here's part of my docker-compose.yml file
version: '3'
services:
mongo:
image: mongo
container_name: mongo01
# command: ["mongod", "-f", "/etc/mongo/mongod.conf"]
volumes:
- ./data/mongodata:/data/db
# - ./config/mongo:/etc/mongo
restart: always
ports:
- "27017:27017"
I could access to mongo service from the host ( my system) but according to the mongo new security policy there is config for limit access to mongo just form 127.0.0.1,I know it , it's
# network interfaces
net:
port: 27017
bindIp: 127.0.0.1
if I could push the mongo image read my custom config I could resolve the problem, but I tried to
to mount a custom config file - ./config/mongo:/etc/mongo and then run mongod with command: ["mongod", "-f", "/etc/mongo/mongod.conf"] but didn't work.
it seems mongod starting in container as process 1 and try to run it with custom command not works, even when I tried to shutdown the mongod in container with mongod --shutdown it shutdown the whole container.( I wanted to stop the mongod and then rerun it with mongod --bind_ip_all )
So the problem is how we can change the mongo image config file ?
The mongo docker image already has an ENTRYPOINT set and it basically is mongod, so in your command (CMD) you can add extra arguments to mongod
simple docker run
docker run -d mongo --bind_ip_all
or with compose
version: '3'
services:
mongo:
image: mongo
command: ["--bind_ip_all"]
ports:
- "27017:27017"
The entrypoint for the official mongo image already contains a step to add --bind_ip_all as long as you don't explicitly bind a specific IP:
# MongoDB 3.6+ defaults to localhost-only binding
haveBindIp=
if _mongod_hack_have_arg --bind_ip "$#" || _mongod_hack_have_arg --bind_ip_all "$#"; then
haveBindIp=1
elif _parse_config "$#" && jq --exit-status '.net.bindIp // .net.bindIpAll' "$jsonConfigFile" > /dev/null; then
haveBindIp=1
fi
if [ -z "$haveBindIp" ]; then
# so if no "--bind_ip" is specified, let's add "--bind_ip_all"
set -- "$#" --bind_ip_all
fi
I want to sync MongoDB database with Elasticsearch1.7. For which I created replication set of my db using following command:
$ sudo mongod --port 27017 --dbpath /var/lib/mongodb --replSet rs0
I have configured transporter 0.1.0 and I run my transporter using following command:
$ ./transporter run --config ./test/config.yaml ./test/application.js
config.yaml
api:
interval: 10s
nodes:
localmongo:
type: mongo
uri: mongodb://localhost/mydb
tail: true
es:
type: elasticsearch
uri: http://192.168.x.xx:9200/
timeseries:
type: influx
uri: influxdb://root:root#localhost:8086/compose
debug:
type: file
uri: stdout://
foofile:
type: file
uri: file:///tmp/foo
So when I try to delete one of the document from mongo it is reflected in mongo collection(I have replication enabled i.e oplogs have been configured as well as I can see the record being deleted in the transporter console) but after this it causes following exception at transporter console and due to this elastic search is not in sync with MongoDB.
transporter: CRITICAL: elasticsearch error (2015-08-11
17:36:31.408666556 +0530 IST: Error
[IllegalArgumentException[Action/metadata line [1] contains an unknown
parameter [refresh]]] Status [500] [500])
How can I fix this?