Skip to content

Instantly share code, notes, and snippets.

@Appendme
Created November 5, 2024 08:25
Show Gist options
  • Save Appendme/623c85565b5846ee1ba2e04a6aba746d to your computer and use it in GitHub Desktop.
Save Appendme/623c85565b5846ee1ba2e04a6aba746d to your computer and use it in GitHub Desktop.

Revisions

  1. Appendme created this gist Nov 5, 2024.
    22 changes: 22 additions & 0 deletions Dockefile
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,22 @@
    mongo:
    image: mongo:7.0.5
    environment:
    MONGO_INITDB_ROOT_USERNAME: root
    MONGO_INITDB_ROOT_PASSWORD: p@ssword$
    MONGO_REPLICA_SET_NAME: rs0
    entrypoint:
    - bash
    - -c
    - |
    cp /keyfile /mongo_keyfile
    chmod 400 /mongo_keyfile
    chown 999:999 /mongo_keyfile
    exec docker-entrypoint.sh $$@
    command: "mongod --bind_ip_all --replSet rs0 --keyFile /mongo_keyfile"
    ports:
    - "27017:27017"
    volumes:
    - ./data/mongo:/data/db
    - ./dev.keyfile:/keyfile
    - ./rs-init.sh:/docker-entrypoint-initdb.d/rs-init.sh:ro
    restart: unless-stopped
    17 changes: 17 additions & 0 deletions rs-init.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    #!/bin/bash

    mongosh -u root -p p@ssword$ <<EOF
    var config = {
    "_id": "rs0",
    "version": 1,
    "members": [
    {
    "_id": 0,
    "host": "mongo:27017",
    "priority": 2
    }
    ]
    };
    rs.initiate(config, { force: true });
    rs.status();
    EOF