initdb.d scripts seem to have broken since https://github.com/docker-library/mongo/pull/443 was merged. Example:
> docker run --rm -v $PWD/db-init.sh:/docker-entrypoint-initdb.d/init.sh:ro -e MONGO_INITDB_DATABASE=some-database mongo
/usr/local/bin/docker-entrypoint.sh: running /docker-entrypoint-initdb.d/init.sh
MongoDB shell version v4.4.3
connecting to: mongodb://127.0.0.1:27017/some-database?compressors=disabled&gssapiServiceName=mongodb
Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed: SocketException: Error connecting to 127.0.0.1:27017 :: caused by :: Connection refused :
connect@src/mongo/shell/mongo.js:374:17
@(connect):2:6
exception: connect failed
exiting with code 1
Our script looks like this:
mongo -- "$MONGO_INITDB_DATABASE" <<EOF
db.collection.insertOne({ nope: true });
EOF
Should we be writing the init scripts differently, now?
For now, we can work around this by mirroring the changes from the PR, in our script:
mongo --host "$TMPDIR/mongodb-27017.sock" -- "$MONGO_INITDB_DATABASE" <<EOF
db.collection.insertOne({ nope: true });
EOF
Would that be an appropriate fix to apply to the entrypoint scripts?
mongoimport doesn't seem to work when specifying the host as the unix socket.
A quick google search reveals this ticket from a few years back which was closed as won't fix
https://jira.mongodb.org/browse/TOOLS-620
Doh, good find @coldis :disappointed:
Looks like we probably need to revert https://github.com/docker-library/mongo/pull/443.
Most helpful comment
Doh, good find @coldis :disappointed:
Looks like we probably need to revert https://github.com/docker-library/mongo/pull/443.