Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Authentication issue in Docker-MongoDB

I have installed MongoDB in Linux Ubuntu through the docker image. I have set the parameters in the YAML file like below to implement the authentication for mongodb. But when I up the server using the command docker-compose up -d, I'm getting error like

"Unsupported config option for 'db' service: 'security'".

How can I resolve the issue?

docker-compose.yaml:


db:
   image: mongo:2.6.4
   command: ["mongod", "--smallfiles"]
   expose: "27017"
   ports: "27017:27017"
   security: keyFile: "/home/ubuntu/dockerlab/keyfile.key"
   authorization: "enabled"
like image 652
J K G Avatar asked Mar 03 '16 13:03

J K G


1 Answers

security and authorization are not a keyword for the docker-compose YAML file, so take them out of there.

If that file key file needs copying into the container, you should put something like:

FROM: mongo:2.6.4

ADD /home/ubuntu/dockerlab/keyfile.key /tmp
ENV AUTH yes

in a Dockerfile.

And change in the docker-compose.yml file:

image: mongo:2.6.4

into

build: .

and the command value into

 command: ["mongod", "--smallfiles", "--keyFile /tmp/keyfile.key" ]

Alternatively you can use a volume entry in your docker-compose.yml to map the keyfile.key into your container, and instead of the ENV in the Dockerfile you add , "--auth" to sequence that is the value for command. Then you can continue to use the image stanza and leave out the Dockerfile altogether:

db:
   image: mongo:2.6.4
   command: ["mongod", "--smallfiles", "--auth", "--keyFile /tmp/keyfile.key" ]
   expose: "27017"
   ports: "27017:27017"
   volumes: 
   - /home/ubuntu/dockerlab/keyfile.key: /tmp
like image 74
Anthon Avatar answered Sep 28 '22 07:09

Anthon