Skip to content

Instantly share code, notes, and snippets.

@LeonFedotov
Created February 25, 2023 19:13
Show Gist options
  • Save LeonFedotov/0992dd67f7faaffa7c8b105e6a1e7f95 to your computer and use it in GitHub Desktop.
Save LeonFedotov/0992dd67f7faaffa7c8b105e6a1e7f95 to your computer and use it in GitHub Desktop.
docker network create mongoCluster
docker run -d --rm -p 27017:27017 --name mongo1 --network mongoCluster mongo:latest mongod --replSet myReplicaSet --bind_ip localhost,mongo1
docker run -d --rm -p 27018:27017 --name mongo2 --network mongoCluster mongo:latest mongod --replSet myReplicaSet --bind_ip localhost,mongo2
docker run -d --rm -p 27019:27017 --name mongo3 --network mongoCluster mongo:latest mongod --replSet myReplicaSet --bind_ip localhost,mongo3
docker exec -it mongo1 mongosh --eval "rs.initiate({
_id: \"myReplicaSet\",
members: [
{_id: 0, host: \"mongo1\"},
{_id: 1, host: \"mongo2\"},
{_id: 2, host: \"mongo3\"}
]
})"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment