Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Run "mongo --repair" in Docker container that cannot start because of MongoDB error
#!/bin/bash
# See https://github.com/docker-library/mongo/pull/63
docker run --rm --volumes-from my-mongo-server mongo unlink "/data/db/mongod.lock"
docker run --rm --volumes-from my-mongo-server mongo --repair
@zulucoda

This comment has been minimized.

Copy link

@zulucoda zulucoda commented Sep 18, 2017

awesome thanks for sharing :bowtie:

@azcoigreach

This comment has been minimized.

Copy link

@azcoigreach azcoigreach commented Dec 22, 2017

Thank you. This was very helpful.

I ended up running a second mongo container with the /bin/bash command and --volumes-from my-mongo-server. This created a means for me to access my database without the mongo container restarting constantly...

docker run -ti --volumes-from my-mongo-server --name my-mongo-server-cmd -p 27018:27017 mongo /bin/bash

@medkhelifi

This comment has been minimized.

Copy link

@medkhelifi medkhelifi commented Mar 19, 2018

Very helpful, Thank you ...

@bbraunstein

This comment has been minimized.

Copy link

@bbraunstein bbraunstein commented Mar 21, 2018

"Unable to start up mongodb due to missing featureCompatibilityVersion document. Please run with --repair to restore the document."

This was the perfect fix I needed to restore my mongodb container while retaining the data. After the documents were repaired, I was able to re-execute docker start mongodb. Thanks! +1

@jjpeet

This comment has been minimized.

Copy link

@jjpeet jjpeet commented Aug 30, 2018

Hi @azcoigreach I'm a docker noob and need to repair my MongoDB.

This is the command I use to run my docker mongo;

docker run -it -d --name="mongo" \
    -p 27017:27017 \
    -p 27018:27018 \
    -p 27019:27019 \
    -e TIMEZONE="Australia/Brisbane" \
    -e TZ="Australia/Brisbane" \
    -v /Users/james/docker/mongo/configdb:/data/configdb \
    -v /Users/james/docker/mongo/db:/data/db \
    --restart always \
    mongo:latest

Would you be able to suggest how I start up a docker to access these local DBs and repair them?
I can't figure out how to translate you command line above to my context...

Thx
JP

@jjpeet

This comment has been minimized.

Copy link

@jjpeet jjpeet commented Aug 30, 2018

Had another look at it this morning and I think I've done it using the following;

docker run -it -d --name="mongofix" \
    -p 27017:27017 \
    -p 27018:27018 \
    -p 27019:27019 \
    -e TIMEZONE="Australia/Brisbane" \
    -e TZ="Australia/Brisbane" \
    -v /Users/james/docker/mongo/configdb:/data/configdb \
    -v /Users/james/docker/mongo/db:/data/db \
    mongo:latest /bin/bash

Now all I need to do it get mongod working to then be able to run mongo --repair. It's reporting all sorts of errors from multiple restores of backups made when it was working).

Any thoughts on what this means?

2018-08-31T08:32:07.415+1000 I -        [initandlisten] Detected data files in /data/db created by the 'wiredTiger' storage engine, so setting the active storage engine to 'wiredTiger'.
2018-08-31T08:32:07.427+1000 I STORAGE  [initandlisten] wiredtiger_open config: create,cache_size=487M,session_max=20000,eviction=(threads_min=4,threads_max=4),config_base=false,statistics=(fast),cache_cursors=false,compatibility=(release="3.0",require_max="3.0"),log=(enabled=true,archive=true,path=journal,compressor=snappy),file_manager=(close_idle_time=100000),statistics_log=(wait=0),verbose=(recovery_progress),
2018-08-31T08:32:08.242+1000 E STORAGE  [initandlisten] WiredTiger error (-31802) [1535668328:242482][6171:0x7f55860b6a00], file:WiredTiger.wt, connection: unable to read root page from file:WiredTiger.wt: WT_ERROR: non-specific WiredTiger error
2018-08-31T08:32:08.242+1000 E STORAGE  [initandlisten] WiredTiger error (0) [1535668328:242597][6171:0x7f55860b6a00], file:WiredTiger.wt, connection: WiredTiger has failed to open its metadata
2018-08-31T08:32:08.242+1000 E STORAGE  [initandlisten] WiredTiger error (0) [1535668328:242613][6171:0x7f55860b6a00], file:WiredTiger.wt, connection: This may be due to the database files being encrypted, being from an older version or due to corruption on disk
2018-08-31T08:32:08.242+1000 E STORAGE  [initandlisten] WiredTiger error (0) [1535668328:242860][6171:0x7f55860b6a00], file:WiredTiger.wt, connection: You should confirm that you have opened the database with the correct options including all encryption and compression options
2018-08-31T08:32:08.246+1000 E -        [initandlisten] Assertion: 28595:-31802: WT_ERROR: non-specific WiredTiger error src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp 421
2018-08-31T08:32:08.248+1000 I STORAGE  [initandlisten] exception in initAndListen: Location28595: -31802: WT_ERROR: non-specific WiredTiger error, terminating
2018-08-31T08:32:08.248+1000 I NETWORK  [initandlisten] shutdown: going to close listening sockets...
2018-08-31T08:32:08.248+1000 I NETWORK  [initandlisten] removing socket file: /tmp/mongodb-27017.sock
2018-08-31T08:32:08.249+1000 I CONTROL  [initandlisten] now exiting
2018-08-31T08:32:08.249+1000 I CONTROL  [initandlisten] shutting down with code:100
@F-Yousri

This comment has been minimized.

Copy link

@F-Yousri F-Yousri commented Dec 15, 2019

worked like a charm, thanks for sharing

@milton-influry

This comment has been minimized.

Copy link

@milton-influry milton-influry commented Mar 4, 2020

Thank you!

@col-panic

This comment has been minimized.

Copy link

@col-panic col-panic commented Mar 25, 2020

Thanks a lot, yet i see

2020-03-25T08:23:29.346+0000 I STORAGE  [initandlisten] Error: journal files are present in journal directory, yet starting without journaling enabled.
2020-03-25T08:23:29.346+0000 I STORAGE  [initandlisten] It is recommended that you start with journaling enabled so that recovery may occur.
2020-03-25T08:23:29.346+0000 I STORAGE  [initandlisten] **************
2020-03-25T08:23:29.346+0000 I STORAGE  [initandlisten] exception in initAndListen: Location13597: can't start without --journal enabled when journal/ files are present, terminating

adding the --journal flag however does not help

@jmattiace

This comment has been minimized.

Copy link

@jmattiace jmattiace commented Apr 16, 2020

🙌🏽

@omar-palomino-exa

This comment has been minimized.

Copy link

@omar-palomino-exa omar-palomino-exa commented Apr 27, 2020

Wow, it worked like charm. 👯

@asyfsaeed

This comment has been minimized.

Copy link

@asyfsaeed asyfsaeed commented May 2, 2020

saved my day :)

@LeeThompson

This comment has been minimized.

Copy link

@LeeThompson LeeThompson commented Jul 31, 2020

And in the middle of the --repair it stops with a segmentation fault.
What a piece of **(#&$(

@woosuk288

This comment has been minimized.

Copy link

@woosuk288 woosuk288 commented Jun 2, 2021

Thank you so much!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment