Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

repair command in mongodb in docker container

Tags:

docker

mongodb

My client has mongodb running in docker container, one morning the db crashed and logs says "unclean shutdown detected". I tried for repairing mongodb but not able to do as it is running under docker container. The reason is that as i have to shutdown mongodb for running repair command and once i shutdown the mongodb then docker throws me out of the container because only one process was running and as it was stopped container was also stopped, now i am not able to run any mongod commands as i am out of container and container is stopped along with mongod instance.

So, can anyone help me out of this, how can i run repair command from outside of docker container ?

Can i run repair command without stopping mongod ?

Please help !!!

Thanks Irshad

like image 441
Irshad Ahmed Ansari Avatar asked Sep 01 '16 11:09

Irshad Ahmed Ansari


People also ask

How do I connect to a MongoDB Docker container?

For connecting to your local MongoDB instance from a Container you must first allow to accept connections from the Docker bridge gateway. To do so, simply add the respective gateway IP in the MongoDB config file /etc/mongod. conf under bindIp in the network interface section.

Can I use MongoDB in Docker?

Can MongoDB Run in a Docker Container? MongoDB can run in a container. The official image available on Docker Hub contains the community edition of MongoDB and is maintained by the Docker team. This image can be used in a development environment.

How does MongoDB run in Docker container from host?

Go to the “mongodb” folder and run the docker-compose up command to start the MongoDB container. The -d operator runs the detached container as a background process. The up command will pull the mongo image from the docker registry and create the container using the given parameters in the docker-compose. yml file.


2 Answers

The example command below fixed my issue with corrupted Wt files.

docker run -it -v <path>:/data/db <image-name> mongod --repair

Just replace path and image-name with yours

like image 185
CORSAIR Avatar answered Oct 11 '22 07:10

CORSAIR


I had this same thing when my Mac decided to restart and install an update this morning, grr.

Normally my mongo container is started with a docker-compose up command, which uses a docker-compose.yml file for all the settings, something like...

version: "3"
services:
  mongo:
    image: mongo:3.6.12
    container_name: mongo
    ports:
     - 27017:27017
    volumes:
     - ~/mongo/data/db:/data/db
     - ~/mongo/db/configdb:/data/configdb

To run a basic docker command with those settings I did...

# Kill any existing mongo containers
docker rm mongo

# Repair the db
docker run -it -v ~/mongo/data/db:/data/db -v ~/mongo/db/configdb:/data/configdb --name mongo -d mongo:3.6.12  mongod --repair

# Has it finished the repair yet?
docker ps -a

After about a minute the container exited, the database was repaired and I was able to run mongo using docker-compose again.

like image 24
chichilatte Avatar answered Oct 11 '22 07:10

chichilatte