简体   繁体   English

如何在使用docker-compose时为mongodb图像添加--auth?

[英]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; 我正在使用docker-compose来运行由node,mongodb,nginx创建的项目;

and I have build the project using docker build 我使用docker build构建了项目

and then I use docker up -d nginx to start my project. 然后我使用docker up -d nginx来启动我的项目。 but I haven't found the config to run mongodb image with '--auth', so how to add '--auth' when compose start the mongodb? 但我没有找到使用'--auth'运行mongodb图像的配置,那么如何在撰写时添加'--auth'启动mongodb?

here is my docker-compose.yml: 这是我的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"

Supply a command to the container including the --auth option. 向容器提供command ,包括--auth选项。

  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. 最新的mongo容器也通过环境变量进行“root”auth初始化 ,模仿postgres设置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM