Skip to content

Ortanon/mongo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 

Repository files navigation

Alpine Mongo

Docker Official doesn't maintain an Alpine-based MongoDB image. I'm sure they have their reasons. My use cases haven't seemed to need Ubuntu so far.

Getting started

  1. Install Docker.

  2. Pull this image.

     $ docker pull karimtemple/mongo
    

Getting busy

Just some quick notes on how I'm currently using containerized Mongo:

Setup

MongoDB's workflow, syntax, and documentation are all kind of a pain in the ass for a beginner like me. Here's where I've come down on the subject of first steps:

Storage

Set up a Docker volume to let docker virtualize the storage for MongoDB. The defaults work fine. This example volume name just happens to be "mongofiles":

$ docker volume create mongofiles

Admin

The image's CMD is using the --auth flag by default, but Docker lets you override CMD commands. Just docker run with --noauth at first to set up admin:

$ docker run --name db -d -v mongofiles:/data/db karimtemple/mongo mongod --bind_ip_all --noauth
$ docker exec -it db mongo
> use admin
> db.createUser({ user: "whatever", pwd: "something", roles: [{role: "readWrite" db: "example"}], mechanisms: ["SCRAM-SHA-1"] })
$ docker container rm -f db

Development

You can run the MongoDB container like a service now and use it in your app:

devdb.sh

$ docker run --name db -d -v devdata:/data/db --restart=unless-stopped karimtemple/mongo

Of course, you can use something like -i instead of -d to watch the mongod output.

Connections

Add -p 27017:27017 if you want to use Mongo clients in your host OS, but it's not necessary. Apps in containers can use Docker networking to get at it. Just use the IP:

$ docker inspect -f={{.NetworkSettings.IPAddress}} db

Then you can get real fancy in your app container like:

app.sh

$ docker run --name exampleapp -i -p 3000:3000 -e "MONGODB_URL=mongodb://testuser:[email protected]:27017/?authSource=admin" exampleimage:latest

If you're using NodeJS, you can have a NodeJS container run your local code so you can see containerized behavior without having to constantly build images, e.g.:

dev.sh

$ docker run --rm --name app -v "$PWD":/app -w /app -p 3000:3000 -i -e "MONGODB_URL=mongodb://testuser:[email protected]:27017/?authSource=admin" node:alpine npm start

About

A smaller MongoDB Docker image using Alpine

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published