How to add --auth for mongodb image when using docker-compose?

I use docker-compose to run my project created by node, mongodb, nginx;

and I built a project using docker build

and then I use docker up -d nginx to run my project. but I did not find the configuration to run the mongodb image using '--auth', so how do I add the '--auth' when creating the mongodb command?

here is my docker-compose.yml:

 version: "2" services: mongodb: image: mongo:latest expose: - "27017" volumes: - "/home/open/mymongo:/data/db" nginx: build: /home/open/mynginx/ ports: - "8080:8080" - "80:80" links: - node_server:node node_server: build: /home/laoqiren/workspace/isomorphic-redux-CNode/ links: - mongodb:mongo expose: - "3000" 
+5
source share
1 answer

Put a command in the container, including the --auth option.

  mongodb: image: mongo:latest expose: - "27017" volumes: - "/home/open/mymongo:/data/db" command: mongod --auth 

The latest mongo containers have "root" auth initialization through environment variables , also modeled after setting up postgres.

+6
source

Source: https://habr.com/ru/post/1266133/


All Articles