Skip to content

Instantly share code, notes, and snippets.

@shaybensasson
Forked from adamelliotfields/docker-compose.yml
Created November 6, 2020 08:20
Show Gist options
  • Save shaybensasson/081d0cd907bc7d86803fb483f3abdca5 to your computer and use it in GitHub Desktop.
Save shaybensasson/081d0cd907bc7d86803fb483f3abdca5 to your computer and use it in GitHub Desktop.
Docker Compose Mongo with Mongo Express
version: "3.5"
services:
mongo:
image: mongo:latest
container_name: mongo
environment:
MONGO_INITDB_ROOT_USERNAME: admin
MONGO_INITDB_ROOT_PASSWORD: admin
ports:
- "0.0.0.0:27017:27017"
networks:
- MONGO
volumes:
- type: volume
source: MONGO_DATA
target: /data/db
- type: volume
source: MONGO_CONFIG
target: /data/configdb
mongo-express:
image: mongo-express:latest
container_name: mongo-express
environment:
ME_CONFIG_MONGODB_ADMINUSERNAME: admin
ME_CONFIG_MONGODB_ADMINPASSWORD: admin
ME_CONFIG_MONGODB_SERVER: mongo
ME_CONFIG_MONGODB_PORT: "27017"
ports:
- "0.0.0.0:8081:8081"
networks:
- MONGO
depends_on:
- mongo
networks:
MONGO:
name: MONGO
volumes:
MONGO_DATA:
name: MONGO_DATA
MONGO_CONFIG:
name: MONGO_CONFIG
@shaybensasson
Copy link
Author

Updated yaml with mongo-express waiting for mongo to start:

# Mongo and mongo-express that waits for it to complete it's initializaiton
version: '3.5'

services:

  mongo:
    image: mongo
    ports:
      - "27017:27017"
    command: sh -c "
      sleep 30 &&
      docker-entrypoint.sh mongod"

  mongo_admin:
    image: mongo-express
    depends_on:
      - mongo
    links:
      - mongo
    ports:
      - "8081:8081"
    volumes:
      - type: bind
        source: ./wait-for.sh
        target: /wait-for.sh
    entrypoint:
      - /bin/sh
      - /wait-for.sh
      - --timeout=3600
      - mongo:27017
      - --
      - tini
      - --
      - /docker-entrypoint.sh

# Wait for another service to become available (e.g. mongo)
# see https://github.com/mrako/wait-for and https://gist.github.com/adamelliotfields/cd49f056deab05250876286d7657dc4b

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment