In this article

Single Command Database Setup

Kamran AhmedKamran Ahmed

When you are working on a backend application, you are likely to need a database. You can either install it on your machine or use a Docker container. I prefer to use Docker containers because it is easier to setup and doesn't pollute my machine with unnecessary dependencies.

This short guide will show you how to spin up a MySQL, PostgreSQL, or MongoDB instance on your local machine using docker. Feel free to submit a PR adding more databases.

PostgreSQL

You can run the following command to run PostgreSQL in a Docker container:

bash
docker run \  --name pg \  --detach \  --publish 5432:5432 \  --env POSTGRES_PASSWORD=admin \  postgres

Now you can connect and run commands against the instance using the following:

bash
docker exec -it pg \  psql -U postgres

MySQL

You can run the following command to run MySQL in a Docker container:

bash
docker run \  --name ms \  --publish 3306:3306 \  --detach \  --env MYSQL_ROOT_PASSWORD=admin \  mysql

Now, you can use the following to run commands against the MySQL instance:

bash
docker exec -it ms \  mysql -u root -padmin

MongoDB

You can run the following command to run MongoDB in a Docker container:

bash
docker run \  --name mdb \  --publish 27017:27017 \  --detach \  mongo

Now, you can use the following to run commands against the MongoDB instance:

bash
docker exec -it mdb \  mongo

Feel free to submit a pull request by adding additional databases to this guide.

Join the Community

search.highfps.fun is the 6th most starred project on GitHub and is visited by hundreds of thousands of developers every month.

Rank 6th out of 28M!

224K

GitHub Stars

Star us on GitHub
Help us reach #1

+90kevery month

+2.1M

Registered Users

Register yourself
Commit to your growth

+2kevery month

39K

Discord Members

Join on Discord
Join the community

RoadmapsBest PracticesGuidesVideosFAQsYouTube

search.highfps.funby@kamrify

Community created roadmaps, best practices, projects, articles, resources and journeys to help you choose your path and grow in your career.

© search.highfps.fun·Terms·Privacy·

ThewNewStack

The top DevOps resource for Kubernetes, cloud-native computing, and large-scale development and deployment.