MongoDB and Mongo Express in Docker Compose

It took me some time to get that I coulnd’t use ME_CONFIG_MONGODB_URL to connect to my Mongo database so I thought I make a post so I’ll remember until next time.

First, let’s see how it is done in docker compose (docker-compose.yml).

version: '3.8'
services:
  mongo:
    image: mongo
    restart: always
    ports:
    - '27017:27017'
    environment:
      MONGO_INITDB_ROOT_USERNAME: root
      MONGO_INITDB_ROOT_PASSWORD: example

  mongo-express:
    image: mongo-express
    restart: always
    ports:
      - 8081:8081
    environment:
      ME_CONFIG_MONGODB_ADMINUSERNAME: root
      ME_CONFIG_MONGODB_ADMINPASSWORD: example
      ME_CONFIG_MONGODB_SERVER: mongo
      ME_CONFIG_BASICAUTH_USERNAME: root
      ME_CONFIG_BASICAUTH_PASSWORD: example

That’s all, then when we run compose up we will create these containers and can go to http://localhost:8081/ to administrate our mongodb which is running the default port 27017 on localhost.

Install docker on Raspberry Pi

This is how I installed docker on Raspberry pi 5. First of all, before anything, I’d get a SD card with a sd usb adapter connected to my computer which I would install the installer which can be found over here. Then choose the Raspberry Pi OS. Choose to have SSH for your configure and remember your name for your Raspberry machine, username and password.

When we got our OS installed, connect it with Putty for example. Then in Putty connect to raspberrypi.local (if that is the name you gave). Then, update all your packages with:

  • sudo apt update
  • sudo apt upgrade

Then, install docker simply with

  • curl -sSL https://get.docker.com | sh

Then add your pi user to the docker group so you can access Docker fully.

  • sudo usermod -aG docker pi

Since we made changes to our current user, we need to logout & login again.

  • logout

Then type

  • groups

To see if the Docker group exist.

Then I had to actually do a reboot to get dockers deamon (dockerd) to work properly.

  • sudo reboot

Now let’s see if docker is working by connecting to the pi again then run,

  • docker run hello-world

Seems to be working!