1.進入容器:
docker ps
docker exec -it 容器名/ID bash
備份mongodb命令:mongodump -h 172.19.19.41 --port 27017 -u='admin' -p='********' -d ******* -o ./backup/
出現報錯:Failed: can't create session: could not connect to server: connection() error occured during connection handshake: auth error: sasl conversation error: unable to authenticate using mechanism "SCRAM-SHA-1": (AuthenticationFailed) Authentication failed.
解決方法:
添加參數:--authenticationDatabase admin
參數含義:
解釋1.安全登錄認證,mongodb本身的一種安全認證登錄方式,參數就相當於指定admin數據庫。
解釋2.在連接mongo時,使用參數 --authenticationDatabase,會認證 -u 和 -p 參數指定的賬戶和密碼。如果沒有指定驗證數據庫,mongo使用連接字符串中指定的DB作為驗證數據塊。
修改后為:mongodump -h 172.19.19.41 --port 27017 --authenticationDatabase admin -u='admin' -p='*******' -d ******* -o ./backup/
ok!正常備份!