Skip to content

Instantly share code, notes, and snippets.

@timjonesdev
Last active November 28, 2019 16:43
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timjonesdev/7a34a2aa92fc64d145d12fa0d8d596d4 to your computer and use it in GitHub Desktop.
Save timjonesdev/7a34a2aa92fc64d145d12fa0d8d596d4 to your computer and use it in GitHub Desktop.
A MongoDB Dockerfile which enables a single-node replicaset
FROM mongo:4.0
# files used to initialize the database
COPY ./init-db.d/ /docker-entrypoint-initdb.d
# add this command to a js file in the init directory
# formatted on newlines for better readability
RUN echo "rs.initiate(
{
_id: 'rs0',
members: [
{
_id: 0,
host: 'localhost:27017'
}
]
});
rs.slaveOk();" > /docker-entrypoint-initdb.d/replica-init.js
# the important bits are calling out the replicaset,
# binding the IP to 0.0.0.0,
# and setting the oplogSize to something manageable
# these settings are for local development only,
# and would likely be significantly different in a production deployment
CMD ["--replSet", "rs0", "--bind_ip", "0.0.0.0", "--oplogSize", "100"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment