MongoDB based on Alpine Linux Edge running as unprivileged User
- Github: leo18945/alpine-mongodb
- Docker: leo18945/alpine-mongodb
As Base Image i use Alpine Linux which is lightweight Distribution with a small surface area for security concerns, but with enough functionality for development and interactive debugging.
To prevent zombie reaping processes i run dumb-init as PID 1 which forwards signals to all processes running in the container.
It's very fast to stop the container when you use this image compare to none init image, this is very important.
These Settings are optional, if not set the default values will be used.
# Optional Configuration Parameter
ARG SERVICE_USER # Mongo User
ARG SERVICE_HOME # Mongo Database Directory
ARG SERVICE_PORT # Mongo Port
ARG SERVICE_LOGFILE # Mongo Logfile
ARG SERVICE_LOGLEVEL # Mongo Loglevel
# Default Settings
ENV SERVICE_USER ${SERVICE_USER:-mongo}
ENV SERVICE_HOME ${SERVICE_HOME:-/data/db}
ENV SERVICE_PORT ${SERVICE_PORT:-27017}
ENV SERVICE_LOGFILE ${SERVICE_LOGFILE:-/data/log/mongod.log}
ENV SERVICE_LOGLEVEL ${SERVICE_LOGLEVEL:-vvv}
Documentation: https://docs.docker.com/compose/compose-file/#/args
Run mongodb in background, and then attach to container.
$ docker run --name my_mongodb -d leo18945/alpine-mongodb
$ docker exec -it my_mongodb mongo
>
> db.version()
3.6.7
> use test
switched to db test
>
Run mongodb and then into shell, do what ever you want.
$ docker run -it leo18945/alpine-mongodb ash
~ $ ps -ef
PID USER TIME COMMAND
1 mongo 0:00 {entrypoint.sh} /usr/bin/dumb-init /bin/sh /entrypoint.sh ash
7 mongo 0:00 ash
8 mongo 0:00 mongod --port 27017 --dbpath /data/db --logpath /data/log/mongod.log --logappend -v
35 mongo 0:00 ps -ef
~ $
~ $ mongo
> db.version()
3.6.7
> use test
switched to db test
> exit
bye
~ $
~ $ ps -ef
PID USER TIME COMMAND
1 mongo 0:00 {entrypoint.sh} /usr/bin/dumb-init /bin/sh /entrypoint.sh ash
7 mongo 0:00 ash
8 mongo 0:01 mongod --port 27017 --dbpath /data/db --logpath /data/log/mongod.log --logappend -v
40 mongo 0:00 ps -ef
~ $
Run mongodb and immediately into mongo shell.
$ docker run -it leo18945/alpine-mongodb mongo
>
> db.version()
3.6.7
> use test
switched to db test
>
Run mongodb as executable.
$ echo 'docker run -it leo18945/alpine-mongodb mongo' > /usr/local/bin/mongo
$ chmod +x /usr/local/bin/mongo
$ mongo
>
> db.version()
3.6.7
> use test
switched to db test
>
Get the latest News about Web Development, Open Source, Tooling, Server & Security