Temporary Docker Database

Sometimes, I need to quickly spin up a MongoDB instance for testing out some stuff. Here’s an alias I use to start a temporary MongoDB container with Docker:

alias docker_temp_mongo="docker run --rm -d -p 27017:27017 \
    -h $(hostname) --name mongo mongo --replSet testdb && \
    sleep 4 && \
    docker exec mongo mongosh --quiet --eval 'rs.initiate();'"

What it does

Command for MySQL

I occasionally need the same thing for MySQL, so here’s a command for that:

alias docker_temp_mysql="docker run --rm -d -p 3306:3306 \
    --name mysql -e MYSQL_ROOT_PASSWORD=password \
    -e MYSQL_DATABASE=testdb mysql:latest"

Find this post helpful? Subscribe and get notified when I post something new!