Setup Postgres docker container quick!!
Quick Postgres setup using Docker containers for rapid development/experimenting
2 min read
Docker remains the quickest way of setting up a Postgres database server. Here's how to do so.
Sometimes, we just need to set up a postgres database server, and if you have docker - spinning up a container is always the quickest and cleanest way of setting up a Postgres server
For example, when you need to quickly setup a Express Rest API server using PostGres with Prisma, like I need to do today. Here's how you do it.
docker run --rm --name postgres-db -p 5433:5432 -e POSTGRES_PASSWORD=mysecretpassword -d postgres:13-alpine
Please Note: we're mapping port 5432 of the container to port 5433 of your local machine/system/computer on which you are writing code. This is intentional and serves to drive understanding of how ports works. The explanation is below:
postgres-dbis the name of the container you spin up.
5432is the default port at which postgres runs. You can, if you so wish, map your system's port to container's port. In this case,
5433is the port at which you will find the server on your local machine.
mysecretpasswordis the password to log in to the db server
postgresis the default user AND default Database. It is not mentioned in the docker command posted above.
postgres:13-alpineis the image we're pulling.
Assuming everything runs without an error, you can connect to the server using the connection string in the following format:
Therefore, your string becomes
And that's it.
If you'd like to know how to connect to this (or any) postgres server using Shell/Terminal, you can find it in an upcoming blog.