DEV Community

Zeeshan Ahmd
Zeeshan Ahmd

Posted on

4 2

Running MongoDB, Redis, MySQL, and NATS as a Docker container

Recently my laptop fan was making lots of noises. So I went to format and reinstall the operating system. This time I thought why not use docker for all the services which I was using through brew before.

Below are some of the commands which I used to start different services in Docker and persist their data. Each command you will run will pull the latest image from the docker hub if it does not exist in your local machine and run the container in the detached mode.

MongoDB

docker run -d -n mongo -p 27017:27017 -v ~/data/mongo-data:/data/db mongo:latest
Enter fullscreen mode Exit fullscreen mode

Redis

docker run -d -n redis -p 6379:6379 redis:latest --dir /tmp
Enter fullscreen mode Exit fullscreen mode

MySQL

docker run -d -n mysql -e MYSQL_ROOT_PASSWORD=root -p 3306:3306 -v ~/data/mysql-data:/var/lib/mysql mysql
Enter fullscreen mode Exit fullscreen mode

NATS

docker run -d -n nats-streaming -p 4222:4222 nats-streaming:latest
Enter fullscreen mode Exit fullscreen mode

PS: Sometimes when you restart your laptop resulting in docker shutting down all the services that are running in the Docker. To overcome this problem I used some bash aliases.

alias dockmongo="docker run -d -n mongo -p 27017:27017 -v ~/data/mongo-data:/data/db mongo:latest"
alias dockredis="docker run -d -n redis -p 6379:6379 redis:latest --dir /tmp"
alias dockmysql="docker run -d -n mysql -e MYSQL_ROOT_PASSWORD=root -p 3306:3306 -v ~/data/mysql-data:/var/lib/mysql mysql"
alias docknats="docker run -d -n nats-streaming -p 4222:4222 nats-streaming:latest"
Enter fullscreen mode Exit fullscreen mode

Heroku

This site is built on Heroku

Join the ranks of developers at Salesforce, Airbase, DEV, and more who deploy their mission critical applications on Heroku. Sign up today and launch your first app!

Get Started

Top comments (0)

Qodo Takeover

Introducing Qodo Gen 1.0: Transform Your Workflow with Agentic AI

Rather than just generating snippets, our agents understand your entire project context, can make decisions, use tools, and carry out tasks autonomously.

Read full post

πŸ‘‹ Kindness is contagious

Please leave a ❀️ or a friendly comment on this post if you found it helpful!

Okay