Authentication Issue in Docker-MongoDB

I installed MongoDB on Linux Ubuntu through the docker image. I set the parameters in the YAML file as shown below to implement authentication for mongodb. But when I use the server with the docker-compose up -d , I get an error like

"Unsupported configuration option for the db service:" security ".

How can i solve the problem?

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" 
+5
source share
1 answer

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

If the file of the file file needs to be copied to the container, you should put something like:

 FROM: mongo:2.6.4 ADD /home/ubuntu/dockerlab/keyfile.key /tmp ENV AUTH yes 

in the docker file.

And modify the docker-compose.yml :

 image: mongo:2.6.4 

in

 build: . 

and command value in

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

Alternatively, you can use the volume entry in docker-compose.yml to map keyfile.key in your container, and instead of Dockerfile in the Dockerfile add , "--auth" to the sequence, which is the value for command . Then you can continue to use the stanza image and completely exclude the Dockerfile :

 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 
+5
source

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


All Articles