简体   繁体   中英

Mongodb image run issue on docker container on mac

I am trying to run the mongodb on docker container using the mongo image, however, keep getting the error on the third-party app

docker image ls

REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
mongo               latest              bcef5fd2979d        3 weeks ago         386MB

Then I use the run command to run the image

docker run bcef5fd2979d

When the command run getting the below status and never found the image is running.

2020-03-20T11:31:45.134+0000 I  CONTROL  [main] Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'
2020-03-20T11:31:45.140+0000 I  CONTROL  [initandlisten] MongoDB starting : pid=1 port=27017 dbpath=/data/db 64-bit host=3be724d752b9
2020-03-20T11:31:45.140+0000 I  CONTROL  [initandlisten] db version v4.2.3
2020-03-20T11:31:45.140+0000 I  CONTROL  [initandlisten] git version: 6874650b362138df74be53d366bbefc321ea32d4
2020-03-20T11:31:45.140+0000 I  CONTROL  [initandlisten] OpenSSL version: OpenSSL 1.1.1  11 Sep 2018
2020-03-20T11:31:45.140+0000 I  CONTROL  [initandlisten] allocator: tcmalloc
2020-03-20T11:31:45.140+0000 I  CONTROL  [initandlisten] modules: none
2020-03-20T11:31:45.140+0000 I  CONTROL  [initandlisten] build environment:
2020-03-20T11:31:45.140+0000 I  CONTROL  [initandlisten]     distmod: ubuntu1804
2020-03-20T11:31:45.140+0000 I  CONTROL  [initandlisten]     distarch: x86_64
2020-03-20T11:31:45.141+0000 I  CONTROL  [initandlisten]     target_arch: x86_64
2020-03-20T11:31:45.142+0000 I  CONTROL  [initandlisten] options: { net: { bindIp: "*" } }
2020-03-20T11:31:45.143+0000 I  STORAGE  [initandlisten] 
2020-03-20T11:31:45.144+0000 I  STORAGE  [initandlisten] ** WARNING: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine
2020-03-20T11:31:45.144+0000 I  STORAGE  [initandlisten] **          See http://dochub.mongodb.org/core/prodnotes-filesystem
2020-03-20T11:31:45.144+0000 I  STORAGE  [initandlisten] wiredtiger_open config: create,cache_size=482M,cache_overflow=(file_max=0M),session_max=33000,eviction=(threads_min=4,threads_max=4),config_base=false,statistics=(fast),log=(enabled=true,archive=true,path=journal,compressor=snappy),file_manager=(close_idle_time=100000,close_scan_interval=10,close_handle_minimum=250),statistics_log=(wait=0),verbose=[recovery_progress,checkpoint_progress],
2020-03-20T11:31:45.959+0000 I  STORAGE  [initandlisten] WiredTiger message [1584703905:959696][1:0x7ffa812feb00], txn-recover: Set global recovery timestamp: (0, 0)
2020-03-20T11:31:45.975+0000 I  RECOVERY [initandlisten] WiredTiger recoveryTimestamp. Ts: Timestamp(0, 0)
2020-03-20T11:31:46.001+0000 I  STORAGE  [initandlisten] Timestamp monitor starting
2020-03-20T11:31:46.009+0000 I  CONTROL  [initandlisten] 
2020-03-20T11:31:46.009+0000 I  CONTROL  [initandlisten] ** WARNING: Access control is not enabled for the database.
2020-03-20T11:31:46.009+0000 I  CONTROL  [initandlisten] **          Read and write access to data and configuration is unrestricted.
2020-03-20T11:31:46.009+0000 I  CONTROL  [initandlisten] 
2020-03-20T11:31:46.011+0000 I  STORAGE  [initandlisten] createCollection: admin.system.version with provided UUID: 44f75892-000b-4698-ba3d-613801c30b11 and options: { uuid: UUID("44f75892-000b-4698-ba3d-613801c30b11") }
2020-03-20T11:31:46.032+0000 I  INDEX    [initandlisten] index build: done building index _id_ on ns admin.system.version
2020-03-20T11:31:46.034+0000 I  SHARDING [initandlisten] Marking collection admin.system.version as collection version: <unsharded>
2020-03-20T11:31:46.034+0000 I  COMMAND  [initandlisten] setting featureCompatibilityVersion to 4.2
2020-03-20T11:31:46.035+0000 I  SHARDING [initandlisten] Marking collection local.system.replset as collection version: <unsharded>
2020-03-20T11:31:46.036+0000 I  STORAGE  [initandlisten] Flow Control is enabled on this deployment.
2020-03-20T11:31:46.037+0000 I  SHARDING [initandlisten] Marking collection admin.system.roles as collection version: <unsharded>
2020-03-20T11:31:46.039+0000 I  STORAGE  [initandlisten] createCollection: local.startup_log with generated UUID: f2b32aa0-2690-44cd-8561-8928a8f8c19f and options: { capped: true, size: 10485760 }
2020-03-20T11:31:46.060+0000 I  INDEX    [initandlisten] index build: done building index _id_ on ns local.startup_log
2020-03-20T11:31:46.060+0000 I  SHARDING [initandlisten] Marking collection local.startup_log as collection version: <unsharded>
2020-03-20T11:31:46.061+0000 I  FTDC     [initandlisten] Initializing full-time diagnostic data capture with directory '/data/db/diagnostic.data'
2020-03-20T11:31:46.064+0000 I  SHARDING [LogicalSessionCacheRefresh] Marking collection config.system.sessions as collection version: <unsharded>
2020-03-20T11:31:46.065+0000 I  STORAGE  [LogicalSessionCacheRefresh] createCollection: config.system.sessions with provided UUID: bdfd0b62-ed5e-4e13-8d6d-e86f65c27dc6 and options: { uuid: UUID("bdfd0b62-ed5e-4e13-8d6d-e86f65c27dc6") }
2020-03-20T11:31:46.067+0000 I  NETWORK  [listener] Listening on /tmp/mongodb-27017.sock
2020-03-20T11:31:46.067+0000 I  NETWORK  [listener] Listening on 0.0.0.0
2020-03-20T11:31:46.067+0000 I  NETWORK  [listener] waiting for connections on port 27017
2020-03-20T11:31:46.089+0000 I  INDEX    [LogicalSessionCacheRefresh] index build: done building index _id_ on ns config.system.sessions
2020-03-20T11:31:46.108+0000 I  INDEX    [LogicalSessionCacheRefresh] index build: starting on config.system.sessions properties: { v: 2, key: { lastUse: 1 }, name: "lsidTTLIndex", ns: "config.system.sessions", expireAfterSeconds: 1800 } using method: Hybrid
2020-03-20T11:31:46.108+0000 I  INDEX    [LogicalSessionCacheRefresh] build may temporarily use up to 200 megabytes of RAM
2020-03-20T11:31:46.108+0000 I  INDEX    [LogicalSessionCacheRefresh] index build: collection scan done. scanned 0 total records in 0 seconds
2020-03-20T11:31:46.110+0000 I  INDEX    [LogicalSessionCacheRefresh] index build: inserted 0 keys from external sorter into index in 0 seconds
2020-03-20T11:31:46.114+0000 I  INDEX    [LogicalSessionCacheRefresh] index build: done building index lsidTTLIndex on ns config.system.sessions
2020-03-20T11:31:46.117+0000 I  SHARDING [LogicalSessionCacheReap] Marking collection config.transactions as collection version: <unsharded>
2020-03-20T11:31:47.001+0000 I  SHARDING [ftdc] Marking collection local.oplog.rs as collection version: <unsharded>

Now the container is running, but not able to connect to the docker image through third-party app like NOSQLBOOSTER

{
    "message" : "failed to connect to server [mongodb:27017] on first connect [MongoNetworkError: getaddrinfo ENOTFOUND mongodb mongodb:27017]",
    "stack" : "MongoNetworkError: failed to connect to server [mongodb:27017] on first connect [MongoNetworkError: getaddrinfo ENOTFOUND mongodb mongodb:27017]" +
              "at Pool.<anonymous> (/Applications/NoSQLBooster for MongoDB.app/Contents/Resources/app.asar/node_modules/mongodb-core/lib/topologies/server.js:431:11)" +
              "at Pool.emit (events.js:182:13)" +
              "at connect (/Applications/NoSQLBooster for MongoDB.app/Contents/Resources/app.asar/node_modules/mongodb-core/lib/connection/pool.js:557:14)" +
              "at makeConnection (/Applications/NoSQLBooster for MongoDB.app/Contents/Resources/app.asar/node_modules/mongodb-core/lib/connection/connect.js:39:11)" +
              "at callback (/Applications/NoSQLBooster for MongoDB.app/Contents/Resources/app.asar/node_modules/mongodb-core/lib/connection/connect.js:261:5)" +
              "at Socket.err (/Applications/NoSQLBooster for MongoDB.app/Contents/Resources/app.asar/node_modules/mongodb-core/lib/connection/connect.js:286:7)" +
              "at Object.onceWrapper (events.js:273:13)" +
              "at Socket.emit (events.js:182:13)" +
              "at emitErrorNT (internal/streams/destroy.js:82:8)" +
              "at emitErrorAndCloseNT (internal/streams/destroy.js:50:3)" +
              "at process._tickCallback (internal/process/next_tick.js:63:19)",
    "name" : "MongoNetworkError",
    "errorLabels" : [
        "TransientTransactionError"
    ]
}

I did create a network on the docker inspecting the network will give me this

[
    {
        "Name": "NETWORK",
        "Id": "e46289d7a88b87ca94e60b7ea96f9eb27d8d6da129f9cb73efa8e72109573629",
        "Created": "2020-03-20T12:18:40.194709701Z",
        "Scope": "local",
        "Driver": "bridge",
        "EnableIPv6": false,
        "IPAM": {
            "Driver": "default",
            "Options": {},
            "Config": [
                {
                    "Subnet": "172.18.0.0/16",
                    "Gateway": "172.18.0.1"
                }
            ]
        },
        "Internal": false,
        "Attachable": false,
        "Ingress": false,
        "ConfigFrom": {
            "Network": ""
        },
        "ConfigOnly": false,
        "Containers": {},
        "Options": {},
        "Labels": {}
    }
]

I need to perform this action to work

Inspect the docker ip address and expose the port with IP address as below code

docker inspect 3be724d752b9 --> container Id

You see the Network section check for the HostIP in my case it is "HostIp": "127.0.0.1"

Then expose the below command

docker run --name mongo -p 127.0.0.1:27017:27017  -d mongo

Then in From URI

mongodb://127.0.0.1:27017/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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