Connection error when running MongoDB inside a container: connection refused

I have a Singularity container in which I build and run MongoDB, calling /usr/bin/mongo "$@" directly. When I do this, I get the error message

MongoDB shell version v4.2.11

connecting to: mongodb://

2020-12-09T13:42:32.943+0000 E  QUERY    [js] Error: couldn't connect to server, connection attempt failed: SocketException: Error connecting to :: caused by :: Connection refused :



2020-12-09T13:42:32.944+0000 F  -        [main] exception: connect failed

2020-12-09T13:42:32.944+0000 E  -        [main] exiting with code 1

Interestingly, when MongoDB already runs outside the container, I can also start it within the container, without that error happening.
Because of this, one theory is that I need to somehow open port 27017 in advance, which is what I will try out next. However, I wanted to post this question in the meantime in case this should not turn out to solve my issue.

If relevant, my recipe is this:

Bootstrap: docker
From: ubuntu:20.04



    apt update
    apt-get install -y wget
    apt-get install -y software-properties-common

    wget -qO - | apt-key add -
    echo "deb [ arch=amd64,arm64 ] bionic/mongodb-org/4.2 multiverse" | tee /etc/apt/sources.list.d/mongodb-org-4.2.list
    apt update
    apt-get install -y mongodb-org

    /usr/bin/mongo "$@"

mongo is the client, mongod is the server.

So what you are doing is starting the client.

This product is already well containerised, but this is not the first self rolled container thread or the first singularity thread.

1 Like

Ah I’m stupid, thanks.

(As for the recipe, I need Singularity because I use other images from there which are later bundled with Singularity Compose.)

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.