So, I have a Dockerfile for a container containing MongoDB:
FROM ubuntu:20.04
RUN apt update
RUN apt-get install -y wget
RUN apt-get install -y software-properties-common
RUN wget -qO - https://www.mongodb.org/static/pgp/server-4.2.asc | apt-key add -
RUN echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.2 multiverse" | tee /etc/apt/sources.list.d/mongodb-org-4.2.list
RUN apt update
RUN apt-get install -y mongodb-org
EXPOSE 27017
CMD /usr/bin/mongod
The problem is that when trying to build, I get the error
(...)
Setting up mongodb-org-server (4.2.11) ...
Adding system user `mongodb' (UID 105) ...
Adding new user `mongodb' (UID 105) with group `nogroup' ...
Not creating home directory `/home/mongodb'.
Adding group `mongodb' (GID 106) ...
Done.
Adding user `mongodb' to group `mongodb' ...
Adding user mongodb to group mongodb
Done.
System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to connect to bus: Host is down
dpkg: error processing package mongodb-org-server (--configure):
installed mongodb-org-server package post-installation script subprocess returned error exit status 1
Setting up mongodb-org-shell (4.2.11) ...
Setting up mongodb-org-mongos (4.2.11) ...
dpkg: dependency problems prevent configuration of mongodb-org:
mongodb-org depends on mongodb-org-server; however:
Package mongodb-org-server is not configured yet.
dpkg: error processing package mongodb-org (--configure):
dependency problems - leaving unconfigured
Processing triggers for libc-bin (2.31-0ubuntu9.1) ...
Errors were encountered while processing:
mongodb-org-server
mongodb-org
E: Sub-process /usr/bin/dpkg returned an error code (1)
The command '/bin/sh -c apt-get install -y mongodb-org' returned a non-zero code: 100
I recently had a somewhat similar problem asked in Problems installing MongoDB in a container regarding something similar with Singularity.
In there, the solution was to upgrade to Ubuntu 20.04, however in this case this is already done.
Note that I also get three other errors/warnings along the way:
Warning: apt-key output should not be parsed (stdout is not a terminal)
WARNING: apt does not have a stable CLI interface. Use with caution in scripts.
debconf: delaying package configuration, since apt-utils is not installed
When I separately install the server part itself using
RUN apt-get install -y mongodb-org-server
I get
Setting up mongodb-org-server (4.2.11) ...
Adding system user `mongodb' (UID 105) ...
Adding new user `mongodb' (UID 105) with group `nogroup' ...
Not creating home directory `/home/mongodb'.
Adding group `mongodb' (GID 106) ...
Done.
Adding user `mongodb' to group `mongodb' ...
Adding user mongodb to group mongodb
Done.
System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to connect to bus: Host is down
dpkg: error processing package mongodb-org-server (--configure):
installed mongodb-org-server package post-installation script subprocess returned error exit status 1
Processing triggers for libc-bin (2.31-0ubuntu9.1) ...
Errors were encountered while processing:
mongodb-org-server
E: Sub-process /usr/bin/dpkg returned an error code (1)
The command '/bin/sh -c apt-get install -y mongodb-org-server' returned a non-zero code: 100
I’m also reading that gpg keyservers are flaky, yes they are. So some retries might be needed.
Or do the “bad” thing and do what you had for your previous Dockerfile: RUN wget -qO - https://www.mongodb.org/static/pgp/server-4.4.asc | apt-key add -
Couldn’t get it to work in any configuration.
Tested out some other official dockerfiles from the github, couldn’t build any of them.
Instead I switched to using bitnami/mongodb:latest directly, that works.