Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I'm using docker-compose to run my project created by node,mongodb,nginx;

and I have build the project using docker build

and then I use docker up -d nginx to start my project. but I haven't found the config to run mongodb image with '--auth', so how to add '--auth' when compose start the mongodb?

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"
like image 389
laoqiren Avatar asked Mar 30 '17 15:03

laoqiren


1 Answers

Supply a command to 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 come with "root" auth initialisation via environment variables too, modelled on the postgres setup.

like image 154
Matt Avatar answered Sep 21 '22 17:09

Matt