Skip to content

Instantly share code, notes, and snippets.

@rwcitek
Last active January 25, 2023 17:11
Show Gist options
  • Save rwcitek/597708aac17e7afa6163d45608b12c46 to your computer and use it in GitHub Desktop.
Save rwcitek/597708aac17e7afa6163d45608b12c46 to your computer and use it in GitHub Desktop.
Installing mongodb client on Ubuntu 22.04 in a Docker container

From https://www.mongodb.com/community/forums/t/installing-mongodb-over-ubuntu-22-04/159931/87

These commands were run using the bash shell on Debian 11 in the Linuv Dev Env on a Chromebook.

Make sure no mongodb instances exist

docker container stop mongodb ; docker container rm mongodb ; sleep 2

Run an Ubuntu 22.04 container in the background

docker container run -d --name mongodb ubuntu:22.04 sleep inf

Install utilities and mongodb client

<<'eof' docker container exec -i mongodb /bin/bash
  DEBIAN_FRONTEND=noninteractive
  apt-get update
  apt-get install -y vim tree curl jq git file gnupg

  # install mongodb client
  curl -L -s https://www.mongodb.org/static/pgp/server-6.0.asc |
    gpg --dearmor |
    tee /usr/share/keyrings/mongodb.gpg > /dev/null
  echo "deb [ arch=amd64,arm64 signed-by=/usr/share/keyrings/mongodb.gpg ] https://repo.mongodb.org/apt/ubuntu jammy/mongodb-org/6.0 multiverse" |
    tee /etc/apt/sources.list.d/mongodb-org-6.0.list
  apt-get update
  apt-get install -y mongodb-mongosh mongodb-database-tools
eof

At this point one could commit the container to an image ... or convert the above commands to a Dockerfile to build an image

Exec into an interactive container

docker container exec -it mongodb /bin/bash
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment