Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

disable default authentication in mongo docker

I want to disable the default auth (avoid to use mongo --authenticationDatabase "auth_db").

in mongo using docker-compose, here is my docker-compose file:

version: "2"

services:
    mongodb:
    image: mongo:latest
    environment: 
      - MONGO_DATA_DIR=/data/db
      - MONGO_LOG_DIR=/dev/null
      - MONGO_INITDB_ROOT_USERNAME=some_user
      - MONGO_INITDB_ROOT_PASSWORD=some_password
    volumes:
      - ./mongo_data:/data/db
    ports:
      - 27017:27017 
like image 691
juancsr Avatar asked Sep 17 '18 17:09

juancsr


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.

How use MongoDB Docker image?

Running MongoDB in a Docker Container You can pull the latest MongoDB image and run it in a Docker container. For production, the application can connect to a cloud-hosted database using the MongoDB Atlas or MongoDB Enterprise Server. This will pull the latest official image from Docker Hub.

How do I enable MongoDB authentication in Docker Compose?

Enable MongoDB auth in docker-compose In order to enable auth in MongoDB we will use --auth flag in docker-compose. After that we could use docker-compose up -d command again, to run MongoDB container. Connect MongoDB with defined authentication

How do I run a Mongo script in a docker container?

We can place this script in a folder (lets call it mongo-scripts) that we will volume mount into the Docker container. Also, we need to start MongoDb with authentication enabled to be able to authenticate. MongoDb will now start up, run the scripts that create our users and then restart in authentication mode.

How do I authenticate a user in MongoDB?

To authenticate as a user, you must provide a username, password, and the authentication database associated with that user. To authenticate using the mongo shell, either: Connect first to the MongoDB or mongos instance. Run the authenticate command or the db.auth () method against the authentication database.

How secure is MongoDB Atlas and MongoDB server?

MongoDB Atlas and MongoDB Server provide a variety of authentication mechanisms that allow users to secure their deployment, from a simple username/password authentication to a full enterprise-grade authentication mechanism, like LDAP and Kerberos.


Video Answer


1 Answers

Just don't pass the MONGO_INITDB_ROOT_USERNAME and MONGO_INITDB_ROOT_PASSWORD env vars when creating the container.

like image 148
pacuna Avatar answered Oct 11 '22 14:10

pacuna