質問: dockerのmongodbは、ユーザーが正常に作成されたと主張していますが、ログインはまだ失敗します mongodb w/authと構成済みユーザーを使用してdockerイメージを構築しようとしています。ただし、ユーザーの作成は機能しますが、そのユーザーを使用できないようです。アプリケーションはdropwizard0.8プロジェクトです。ユーザーの作成に問題があると思いますが、以下のログからわかるように、mongoはユーザーが正常に作成されたと主張しています。イメージを作成するために使用するコマンド:docker build -t id-srv -f dockerfile . && docker-compose up --build my-mongoビルドのログは次のとおりです。$ docker build -t my-mongo -f dockerfile-mongo . --no-cache sending build context to docker daemon 73.08 mb step 1 : from mongo:3.3 ---> aa57b208cc5d step 2 : run su - mongodb -c "mongod" & sleep 5; mongo --eval "db.createuser({user: 'peter', pwd: 'password', roles: [{role:'readwrite',db:'progether-id'}]})" a dmin ---> running in d75db07d9922 2016-10-03t12:08:27.655+0000 i control [initandlisten] mongodb starting : pid=10 port=27017 dbpath=/data/db 64-bit host=383850eeb47b 2016-10-03t12:08:27.655+0000 i control [initandlisten] db version v3.3.15 2016-10-03t12:08:27.655+0000 i control [initandlisten] git version: 520f5571d039b57cf9c319b49654909828971073 2016-10-03t12:08:27.655+0000 i control [initandlisten] openssl version: openssl 1.0.1t 3 may 2016 2016-10-03t12:08:27.656+0000 i control [initandlisten] allocator: tcmalloc 2016-10-03t12:08:27.656+0000 i control [initandlisten] modules: none 2016-10-03t12:08:27.656+0000 i control [initandlisten] build environment: 2016-10-03t12:08:27.656+0000 i control [initandlisten] distmod: debian81 2016-10-03t12:08:27.656+0000 i control [initandlisten] distarch: x86_64 2016-10-03t12:08:27.656+0000 i control [initandlisten] target_arch: x86_64 2016-10-03t12:08:27.656+0000 i control [initandlisten] options: {} 2016-10-03t12:08:27.661+0000 i storage [initandlisten] 2016-10-03t12:08:27.661+0000 i storage [initandlisten] ** warning: using the xfs filesystem is strongly recommended with the wiredtiger storage engine 2016-10-03t12:08:27.661+0000 i storage [initandlisten] see http://dochub.mongodb.org/core/prodnotes-filesystem 2016-10-03t12:08:27.661+0000 i storage [initandlisten] wiredtiger_open config: create,cache_size=256m,session_max=20000,eviction=(threads_max=4),config_base=fa lse,statistics=(fast),log=(enabled=true,archive=true,path=journal,compressor=snappy),file_manager=(close_idle_time=100000),checkpoint=(wait=60,log_size=2gb),sta tistics_log=(wait=0), 2016-10-03t12:08:27.696+0000 i control [initandlisten] 2016-10-03t12:08:27.696+0000 i control [initandlisten] ** note: this is a development version (3.3.15) of mongodb. 2016-10-03t12:08:27.696+0000 i control [initandlisten] ** not recommended for production. 2016-10-03t12:08:27.696+0000 i control [initandlisten] 2016-10-03t12:08:27.697+0000 i control [initandlisten] ** warning: access control is not enabled for the database. 2016-10-03t12:08:27.697+0000 i control [initandlisten] ** read and write access to data and configuration is unrestricted. 2016-10-03t12:08:27.697+0000 i control [initandlisten] 2016-10-03t12:08:27.697+0000 i control [initandlisten] 2016-10-03t12:08:27.697+0000 i control [initandlisten] ** warning: /sys/kernel/mm/transparent_hugepage/enabled is 'always'. 2016-10-03t12:08:27.697+0000 i control [initandlisten] ** we suggest setting it to 'never' 2016-10-03t12:08:27.698+0000 i control [initandlisten] 2016-10-03t12:08:27.698+0000 i control [initandlisten] ** warning: /sys/kernel/mm/transparent_hugepage/defrag is 'always'. 2016-10-03t12:08:27.698+0000 i control [initandlisten] ** we suggest setting it to 'never' 2016-10-03t12:08:27.698+0000 i control [initandlisten] 2016-10-03t12:08:27.707+0000 i ftdc [initandlisten] initializing full-time diagnostic data capture with directory '/data/db/diagnostic.data' 2016-10-03t12:08:27.716+0000 i index [initandlisten] build index on: admin.system.version properties: { v: 2, key: { version: 1 }, name: "incompatible_with_v ersion_32", ns: "admin.system.version" } 2016-10-03t12:08:27.716+0000 i index [initandlisten] building index using bulk method 2016-10-03t12:08:27.717+0000 i index [initandlisten] build index done. scanned 0 total records. 0 secs 2016-10-03t12:08:27.719+0000 i network [thread1] waiting for connections on port 27017 mongodb shell version v3.3.15 connecting to: mongodb://127.0.0.1:27017/admin 2016-10-03t12:08:32.766+0000 i network [thread1] connection accepted from 127.0.0.1:45594 #1 (1 connection now open) 2016-10-03t12:08:32.767+0000 i network [conn1] received client metadata from 127.0.0.1:45594 conn1: { application: { name: "mongodb shell" }, driver: { name: " mongodb internal client", version: "3.3.15" }, os: { type: "linux", name: "pretty_name="debian gnu/linux 8 (jessie)"", architecture: "x86_64", version: "kernel 4.4.16-boot2docker" } } mongodb server version: 3.3.15 successfully added user: { "user" : "peter", "roles" : [ { "role" : "readwrite", "db" : "progether-id" } ] } 2016-10-03t12:08:32.792+0000 i - [conn1] end connection 127.0.0.1:45594 (1 connection now open) ---> 7095cab20aa3 removing intermediate container d75db07d9922 step 3 : run rm /tmp/mongodb-*.sock ---> running in 418278f9b413 ---> 3f0af9638969 removing intermediate container 418278f9b413 step 4 : cmd mongod --auth --smallfiles ---> running in cf50e0920661 ---> 41b81d0634b3 removing intermediate container cf50e0920661 successfully built 41b81d0634b3 security warning: you are building a docker image from windows against a non-windows docker host. all files and directories added to build context will have '-r wxr-xr-x' permissions. it is recommended to double check and reset permissions for sensitive files and directories. docker-composeからのログは次のとおりです。$ docker-compose up --build starting identityservice_mongo_1 starting identityservice_identify-service_1 attaching to identityservice_mongo_1, identityservice_identify-service_1 ←[36mmongo_1 |←[0m 2016-10-03t12:03:21.182+0000 i control [initandlisten] mongodb starting : pid=1 port=27017 dbpath=/data/db 64-bit host=e74532b51 0ca ←[36mmongo_1 |←[0m 2016-10-03t12:03:21.183+0000 i control [initandlisten] db version v3.3.15 ←[36mmongo_1 |←[0m 2016-10-03t12:03:21.183+0000 i control [initandlisten] git version: 520f5571d039b57cf9c319b49654909828971073 ←[36mmongo_1 |←[0m 2016-10-03t12:03:21.183+0000 i control [initandlisten] openssl version: openssl 1.0.1t 3 may 2016 ←[36mmongo_1 |←[0m 2016-10-03t12:03:21.183+0000 i control [initandlisten] allocator: tcmalloc ←[36mmongo_1 |←[0m 2016-10-03t12:03:21.183+0000 i control [initandlisten] modules: none ←[36mmongo_1 |←[0m 2016-10-03t12:03:21.184+0000 i control [initandlisten] build environment: ←[36mmongo_1 |←[0m 2016-10-03t12:03:21.184+0000 i control [initandlisten] distmod: debian81 ←[36mmongo_1 |←[0m 2016-10-03t12:03:21.184+0000 i control [initandlisten] distarch: x86_64 ←[36mmongo_1 |←[0m 2016-10-03t12:03:21.184+0000 i control [initandlisten] target_arch: x86_64 ←[36mmongo_1 |←[0m 2016-10-03t12:03:21.184+0000 i control [initandlisten] options: { security: { authorization: "enabled" }, storage: { mmapv1: { s mallfiles: true } } } ←[36mmongo_1 |←[0m 2016-10-03t12:03:21.188+0000 i - [initandlisten] detected data files in /data/db created by the 'mmapv1' storage engine, s o setting the active storage engine to 'mmapv1'. ←[36mmongo_1 |←[0m 2016-10-03t12:03:21.192+0000 i journal [initandlisten] journal dir=/data/db/journal ←[36mmongo_1 |←[0m 2016-10-03t12:03:21.193+0000 i journal [initandlisten] recover : no journal files present, no recovery needed ←[36mmongo_1 |←[0m 2016-10-03t12:03:21.231+0000 i journal [durability] durability thread started ←[36mmongo_1 |←[0m 2016-10-03t12:03:21.231+0000 i journal [journal writer] journal writer thread started ←[36mmongo_1 |←[0m 2016-10-03t12:03:21.232+0000 i control [initandlisten] ←[36mmongo_1 |←[0m 2016-10-03t12:03:21.232+0000 i control [initandlisten] ** note: this is a development version (3.3.15) of mongodb. ←[36mmongo_1 |←[0m 2016-10-03t12:03:21.232+0000 i control [initandlisten] ** not recommended for production. ←[36mmongo_1 |←[0m 2016-10-03t12:03:21.232+0000 i control [initandlisten] ←[36mmongo_1 |←[0m 2016-10-03t12:03:21.233+0000 i control [initandlisten] ←[36mmongo_1 |←[0m 2016-10-03t12:03:21.233+0000 i control [initandlisten] ** warning: /sys/kernel/mm/transparent_hugepage/enabled is 'always'. ←[36mmongo_1 |←[0m 2016-10-03t12:03:21.233+0000 i control [initandlisten] ** we suggest setting it to 'never' ←[36mmongo_1 |←[0m 2016-10-03t12:03:21.233+0000 i control [initandlisten] ←[36mmongo_1 |←[0m 2016-10-03t12:03:21.233+0000 i control [initandlisten] ** warning: /sys/kernel/mm/transparent_hugepage/defrag is 'always'. ←[36mmongo_1 |←[0m 2016-10-03t12:03:21.233+0000 i control [initandlisten] ** we suggest setting it to 'never' ←[36mmongo_1 |←[0m 2016-10-03t12:03:21.233+0000 i control [initandlisten] ←[36mmongo_1 |←[0m 2016-10-03t12:03:21.237+0000 i ftdc [initandlisten] initializing full-time diagnostic data capture with directory '/data/db/d iagnostic.data' ←[36mmongo_1 |←[0m 2016-10-03t12:03:21.238+0000 i network [thread1] waiting for connections on port 27017 ←[33midentify-service_1 |←[0m info [2016-10-03 12:03:23,472] org.eclipse.jetty.util.log: logging initialized @2104ms ←[33midentify-service_1 |←[0m debug [2016-10-03 12:03:23,564] com.progether.services.id.idservice: initializing application ←[33midentify-service_1 |←[0m debug [2016-10-03 12:03:23,566] com.progether.services.id.idservice: initializing application/morphia ←[33midentify-service_1 |←[0m info [2016-10-03 12:03:23,577] org.mongodb.morphia.logging.morphialoggerfactory: loggerimplfactory set to org.mongodb.morphia.lo gging.jdk.jdkloggerfactory ←[33midentify-service_1 |←[0m warn [2016-10-03 12:03:24,346] org.mongodb.morphia.mapping.validation.mappingvalidator: misplacedproperty complained about com.p rogether.services.id.representation.usersession.expired : com.progether.services.id.representation.usersession.expired is annotated as @property but is a type t hat cannot be mapped simply (type is java.time.offsetdatetime). ←[33midentify-service_1 |←[0m warn [2016-10-03 12:03:24,347] org.mongodb.morphia.mapping.validation.mappingvalidator: misplacedproperty complained about com.p rogether.services.id.representation.usersession.lastaccess : com.progether.services.id.representation.usersession.lastaccess is annotated as @property but is a type that cannot be mapped simply (type is java.time.offsetdatetime). ←[33midentify-service_1 |←[0m warn [2016-10-03 12:03:24,348] org.mongodb.morphia.mapping.validation.mappingvalidator: misplacedproperty complained about com.p rogether.services.id.representation.usersession.started : com.progether.services.id.representation.usersession.started is annotated as @property but is a type t hat cannot be mapped simply (type is java.time.offsetdatetime). ←[33midentify-service_1 |←[0m warn [2016-10-03 12:03:24,365] org.mongodb.morphia.mapping.mappedfield: parameterized types are treated as untyped objects. see field 'properties' on class com.progether.services.id.representation.useridentity ←[33midentify-service_1 |←[0m info [2016-10-03 12:03:24,476] org.mongodb.driver.cluster: cluster created with settings {hosts=[mongo:27017], mode=single, requ iredclustertype=unknown, serverselectiontimeout='30000 ms', maxwaitqueuesize=500} ←[36mmongo_1 |←[0m 2016-10-03t12:03:24.529+0000 i network [thread1] connection accepted from 172.19.0.3:59474 #1 (1 connection now open) ←[36mmongo_1 |←[0m 2016-10-03t12:03:24.597+0000 i access [conn1] authenticate db: progether-id { authenticate: 1, user: "peter", nonce: "xxx", ke y: "xxx" } ←[36mmongo_1 |←[0m 2016-10-03t12:03:24.597+0000 i access [conn1] failed to authenticate peter@progether-id with mechanism mongodb-cr: authenticati onfailed: usernotfound: could not find user peter@progether-id ←[33midentify-service_1 |←[0m info [2016-10-03 12:03:24,598] org.mongodb.driver.cluster: no server chosen by primaryserverselector from cluster description cl usterdescription{type=unknown, connectionmode=single, all=[serverdescription{address=mongo:27017, type=unknown, state=connecting}]}. waiting for 30000 ms before timing out ←[36mmongo_1 |←[0m 2016-10-03t12:03:24.605+0000 i - [conn1] end connection 172.19.0.3:59474 (1 connection now open) ←[33midentify-service_1 |←[0m info [2016-10-03 12:03:24,616] org.mongodb.driver.cluster: exception in monitor thread while connecting to server mongo:27017 ←[33midentify-service_1 |←[0m ! com.mongodb.mongocommandexception: command failed with error 18: 'auth failed' on server mongo:27017. the full response is { "o k" : 0.0, "errmsg" : "auth failed", "code" : 18, "codename" : "authenticationfailed" } ←[36mmongo_1 |←[0m 2016-10-03t12:03:25.128+0000 i network [thread1] connection accepted from 172.19.0.3:59476 #2 (1 connection now open) ←[36mmongo_1 |←[0m 2016-10-03t12:03:25.133+0000 i access [conn2] authenticate db: progether-id { authenticate: 1, user: "peter", nonce: "xxx", ke y: "xxx" } ←[36mmongo_1 |←[0m 2016-10-03t12:03:25.133+0000 i access [conn2] failed to authenticate peter@progether-id with mechanism mongodb-cr: authenticati onfailed: usernotfound: could not find user peter@progether-id dockerfile-mongo:from mongo:3.3 run su - mongodb -c "mongod" & sleep 5; mongo --eval "\ db.createuser({user: 'peter', pwd: 'password', roles: [{role:'readwrite',db:'progether-id'}]})" admin run rm /tmp/mongodb-*.sock cmd ["mongod", "--auth", "--smallfiles"] docker-compose.yml:version: '2' services: identify-service: image: id-srv ports: - "8483:8483" links: - mongo mongo: image: my-mongo ports: - "27017:27017"
回答: 私は次のことを観察します: 作成ファイルを実行すると、identify-serviceはユーザーが作成されていないことを通知します。 ユーザーの作成がディスクにコミットされることを保証するものは何もありません。 mongodbは、ramのデータを処理する傾向があり、dockerによって強制終了されたときにデータをコミットしなかった可能性があります。 テスト方法: 作成ファイルを起動した後、mongodbを使用できるようにする必要があります。それに接続し、ユーザーがそこにいるかどうかを確認します。 の解き方: ビルド時ではなく、実行時にユーザーを追加します。 add userコマンドをentrypoint.shに配置し、そのスクリプトをmongodbコンテナーのエントリーポイントとして使用します。 たぶん、ユーザーの作成後に https://docs.mongodb.com/manual/reference/command/fsync/ を追加することもできます。