Docker Compose MongoDB server


In one container start the Docker server, the other one will be the client that is built based on the Dockerfile


examples/mongodb/docker-compose.yml
version: '3.8'
services:
  client:
    build: .
    volumes:
    - .:/opt
    links:
    - mongodb
    command: tail -f /dev/null
  mongodb:
    image: mongo:latest

The Dockerfile is also based on the official mongodb image as that made it easy to have mongosh already installed.


examples/mongodb/Dockerfile
FROM mongo:latest

Start the two containers:


docker-compose up -d

Connect to the client container:


docker exec -it mongodb_client_1 bash

Start the mongodb client and connect to the server running in the other container


mongosh mongodb://mongodb:27017