i'm using this docker-compose.yml to run a local mongo replica set:
version: '3.5'
services:
mongo1:
hostname: mongo1
container_name: localmongo1
image: mongo
expose:
- 27017
ports:
- 27017:27017
restart: always
entrypoint: [ "/usr/bin/mongod", "--bind_ip_all", "--replSet", "rs0" ]
mongo2:
hostname: mongo2
container_name: localmongo2
image: mongo
expose:
- 27017
ports:
- 27018:27017
restart: always
entrypoint: [ "/usr/bin/mongod", "--bind_ip_all", "--replSet", "rs0" ]
mongo3:
hostname: mongo3
container_name: localmongo3
image: mongo
expose:
- 27017
ports:
- 27019:27017
restart: always
entrypoint: [ "/usr/bin/mongod", "--bind_ip_all", "--replSet", "rs0" ]
it's simple and works fine, but i do have to: 1- initialize the replica set:
{
_id : 'rs0',
members: [
{ _id : 0, host : "mongo1:27017" },
{ _id : 1, host : "mongo2:27017" },
{ _id : 2, host : "mongo3:27017" }
]
}
)
2- add several users to several dbs :
use db1
db.createUser({
user:"user1",
pwd:"pass",
roles:[
{
role:"readWrite",
db:"db1"
},
{
role:"dbAdmin",
db:"db1"
}
]
})
use db2
db.createUser({
user:"user2",
pwd:"pass",
roles:[
{
role:"readWrite",
db:"db2"
}
]
})
i'm trying to find a way to run those last two scripts right after deploying the above 3 containers. should i add another image that runs those scripts? or should be some other way to run those scripts?
(other questions reference to some users' maintained images. i prefer not to use them.)