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
Redis
docker run -d -n redis -p 6379:6379 redis:latest --dir /tmp
MySQL
docker run -d -n mysql -e MYSQL_ROOT_PASSWORD=root -p 3306:3306 -v ~/data/mysql-data:/var/lib/mysql mysql
NATS
docker run -d -n nats-streaming -p 4222:4222 nats-streaming:latest
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"
Top comments (0)