Skip to content

Instantly share code, notes, and snippets.

@alaztetik
Last active November 20, 2022 12:18
Show Gist options
  • Save alaztetik/8c44177dd6ab50c8440a3cc9be830fb4 to your computer and use it in GitHub Desktop.
Save alaztetik/8c44177dd6ab50c8440a3cc9be830fb4 to your computer and use it in GitHub Desktop.

Revisions

  1. alaztetik revised this gist Nov 20, 2022. No changes.
  2. alaztetik created this gist Nov 20, 2022.
    24 changes: 24 additions & 0 deletions mongodb_on_docker.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,24 @@
    # commands may need sudo

    # pull MongoDB image:
    docker pull mongo

    # start container:
    docker run -d \
    --name CONTAINER_NAME \
    -p LOCALHOST_PORT_NUMBER \
    -e MONGO_INITDB_ROOT_USERNAME=username \
    -e MONGO_INITDB_ROOT_PASSWORD=password \
    mongo

    # check if the contaier is running:
    docker container ls

    # start ad connect to a bash shell within the container:
    docker exec -it CONTAINER_NAME bash

    # access MongoDB instance via CLI:
    mongosh --username username --password password

    # use URI to connect to db from outside the container:
    mongodb://username:[email protected]:PORT/