How to run mongodb docker instance with custom configuration file? - mongodb

I have executed the command
sudo docker run -p 37017:27017 -v /data:/data/db -v /logs:/var/log/mongodb/ -v /etc/:/etc/ --name mongocustom -d bbed8d0e01c1 --config /etc/newmongod.conf.
but soon the container exited with an error.
docker logs gives following output:
sudo docker logs mongocustom
parse error: Invalid numeric literal at line 1, column 14
parse error: Invalid numeric literal at line 1, column 14
Error parsing YAML config file: yaml-cpp: error at line 16, column 12: illegal map value
try 'mongod --help' for more information
So where I went wrong.

Related

Getting error while taking mongodb backup from docker container

I am getting the following error while taking mongodb backup from docker container using shell script. I am giving the error below.
container name : uBot_sandbox_subhrajp
OCI runtime exec failed: exec failed: container_linux.go:349: starting container process caused "exec: \"mongodump\": executable file not found in $PATH": unknown
Error: No such container:path: uBot_sandbox_subhrajp:/data/ubot-db-mongobackup_2021_02_09_13-09-58
My shell script is given below.
#!/bin/bash
export DATABASE_NAME="ubot-db"
export BACKUP_LOCATION="/home/UBOT"
export TIMESTAMP=$(date +'%Y_%m_%d_%H-%M-%S')
for NAMES in $(docker ps -a --format "{{.Names}}" --filter "name=uBot_sandbox");do
echo "container name : $NAMES"
docker exec -t ${NAMES} mongodump --out /data/${DATABASE_NAME}-mongobackup_${TIMESTAMP} --db ${DATABASE_NAME}
docker cp ${NAMES}:/data/${DATABASE_NAME}-mongobackup_${TIMESTAMP} ${BACKUP_LOCATION}
done
Here I need to take mongodb backup from all matched containers and copy those into target location. Please help me to resolve this error and execute the code as expected.

I am getting "docker: invalid reference format." in my local machine

I am trying to run postgresql container in my local (Windows 10 machine). i am using this command :
docker run -d --name pg-docker --restart=always --publish 5432:5432 -e POSTGRES_PASSWORD=postgres -v C:\Program Files\Docker\Volumes\pg:/var/lib/postgresql/data postgres:alpine
but its returning "docker: invalid reference format." error.
(P.S. I have my postgresql image)
-v C:\Program Files\Docker\Volumes\pg:/var/lib/postgresql/data is read as two separate arguments due to the space in "Program Files". So "Files\Docker\Volumes\pg:/var/lib/postgresql/data" is interpreted as the docker image name.
Escape the space with a \ or wrap the path in quotes.

postgres on docker fails with `chown: cannot dereference ... : No such file or directory`

I am trying to deploy postgres on docker and it exits immediately after I run it. On checking the logs I get the following error:
chown: cannot dereference '/var/lib/postgresql/data/venv/bin/python3': No such file or directory
The command am running is here below:
sudo docker run -p 5432:5432 -e POSTGRES_USER=superset -e POSTGRES_PASSWORD=mypostgrespassword -e POSTGRES_DB=superset --volume $PWD:/var/lib/postgresql/data -d postgres
How can I fix that?
The problem here is, that the directory you are mounting, is not empty.
Create a empty directory, for example /opt/pgdata and then mount that one:
docker run -p 5432:5432 -e POSTGRES_USER=superset -e POSTGRES_PASSWORD=mypostgrespassword -e POSTGRES_DB=superset -v /opt/pgdata:/var/lib/postgresql/data -d postgres

Reference Error when inserting a string with eval into mongodb

I would like to insert data into my mongodb from the command line. The mongodb is running in a docker container.
I want to do the following steps:
Enter docker container
Insert data into mongodb
Exit container
The command that I am using is the following:
docker exec -i <id-of-mongo-container> sh -c "mongo --eval 'db.rules.insert({ description: "test123"})'"
But this throws the following exception:
[js] uncaught exception: ReferenceError: test123 is not defined
I think it is an issue with the quote mark mix, but I am not able to figure out how to get it right. Does someone have an idea on how to fix this?
Research
Something I found from research is that if you swap the string "test123" with a number e.g. 2. Than the command does work.
Therefore, the following command does work.
docker exec -i <id-of-mongo-container> sh -c 'mongo admin --eval "db.rules.insert({ description: 2})"'
It also seems to related to this issue, but it is different because there is an extra set of qoutes from the docker exec.
Cheers!

Tensorflow for Poets | Relaunching Docker | invalid reference format

I'm a beginner, trying out Tensorflow for Poets. I have been following instructions to build my own image classifier. But I get an error while following Step 3 of the tutorial at here
When I run the following command in PowerShell:
docker run -it \ --publish 6006:6006 \ --volume ${HOME}/tf_files:/tf_files \ --workdir /tf_files \
tensorflow/tensorflow:1.1.0 bash
I get the following error:
C:\Program Files\Docker\Docker\Resources\bin\docker.exe: invalid reference format. See 'C:\Program
Files\Docker\Docker\Resources\bin\docker.exe run --help'
I have tried passing home address instead of $HOME, tried even lower case for the address. But still I get the same error.
I'd appreciate thoughts and suggestions.
Thanks!