You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

基于Ubuntu的MongoDB Docker镜像中mongodump SASL认证报错,需添加依赖?

Fixing "SASL authentication support not compiled into client library" with mongodump in your MongoDB Docker Image

Why This Happens

That error pops up because the mongodump tool in your current Docker image doesn't have SASL (Simple Authentication and Security Layer) support compiled in, which is required for using the SCRAM-SHA-1 authentication mechanism. Also, a quick heads-up: the mongodb-10gen package you're using is for older MongoDB 2.x versions, and SCRAM-SHA-1 was only introduced in MongoDB 3.0. So you'll want to make sure your MongoDB server is running a version that actually supports this auth method too.

How to Fix It

1. Add SASL Dependencies to Your Dockerfile

Modify your Dockerfile to install SASL-related system packages before or alongside MongoDB. These libraries will add the necessary SASL support to MongoDB client tools like mongodump:

FROM ubuntu
RUN apt-get update
RUN apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10
RUN echo 'deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen' | tee /etc/apt/sources.list.d/mongodb.list
RUN apt-get update
# Install SASL libraries to enable auth support
RUN apt-get install -y libsasl2-dev libsasl2-modules
RUN apt-get install -y mongodb-10gen
RUN mkdir -p /data/db
EXPOSE 27017
CMD ["--port", "27017", "--smallfiles"]  # Split args properly for correct parsing
ENTRYPOINT ["/usr/bin/mongod"]  # Fixed path (missing leading /) and use exec form

Note: I fixed two issues in your original Dockerfile:

  • The ENTRYPOINT path was missing a leading / (should be /usr/bin/mongod instead of usr/bin/mongod)
  • Split the CMD arguments into separate strings (Docker requires this to parse commands correctly)

2. Consider Upgrading to an Official MongoDB Image

If your MongoDB server is running 3.0 or newer, it's way more reliable to use the official MongoDB Docker image instead of the old mongodb-10gen package. Official images come pre-configured with all necessary dependencies (including SASL support) and are actively maintained:

# Example: Use official MongoDB 3.6 image (match your server version)
FROM mongo:3.6
RUN mkdir -p /data/db
EXPOSE 27017
CMD ["--port", "27017", "--smallfiles"]

3. Fix Your mongodump Command

Your original mongodump command has a syntax error with the port parameter—use --port (double dash) instead of -port. Also, --out expects a directory (not a JSON file), since mongodump writes multiple backup files to that location:

mongodump --host *.*.*.* --port 27017 -u user -p pass --authenticationDatabase admin --authenticationMechanism SCRAM-SHA-1 --out /tmp/backup/mongodump

How to Verify

  1. Rebuild your Docker image: docker build -t my-custom-mongo .
  2. Start the container: docker run -d my-custom-mongo
  3. Enter the container's bash shell: docker exec -it <your-container-id> bash
  4. Run the corrected mongodump command—you shouldn't hit the SASL error anymore.

内容的提问来源于stack exchange,提问作者Rudziankoŭ

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 08:33:30