使用docker-compose时如何为mongodb镜像添加--auth? [英] how to add --auth for mongodb image when using docker-compose?

查看:192
本文介绍了使用docker-compose时如何为mongodb镜像添加--auth?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用docker-compose运行由node,mongodb,nginx创建的项目;

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

并且我已经使用docker build

,然后使用docker up -d nginx启动我的项目.但是我还没有找到配置来使用'--auth'运行mongodb映像,所以如何在撰写启动mongodb时添加'--auth'?

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?

这是我的docker-compose.yml:

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"

推荐答案

向包含--auth选项的容器提供command.

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

最新的mongo容器还附带了通过环境变量进行"root"身份验证初始化,并以postgres设置为模型.

The latest mongo containers come with "root" auth initialisation via environment variables too, modelled on the postgres setup.

这篇关于使用docker-compose时如何为mongodb镜像添加--auth?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆