Build a PostgreSQL Database using Docker

¡

3 min read

I am working on the off-platform project of building a database in PostgreSQL for the Codecedemy Data Engineer path and eventually learn to work with MySQL databases as well.

I was thinking about how I would want to do it, as I don't want to have a live databases living on my box and I want to be able to delete what I create at will, especially if I mess it up.

Why Docker?

From what I read, Docker is like a glorified virtual machine (VM) generator. That's what I need - a VM. It's great for development and testing environments, so if you need to delete test databases or undo errors, it's not going to affect production. I want to also add the Docker image to my portfolio on GitHub using its Container Registry. But if I wanted to take it to production, once I get the database to what I want it to be, I plan to use AWS's RDS when it's time to take the database into the real world and connect a website to it, you know, persist data.

Why Azure Data Studio?

I've worked in the world of MS SQL Server for a very long time, so I am use to how Microsoft displays database setup and its visual design. It also doesn't (appear to) have the issues that the free, open-source database IDEs have and that Codecedemy suggested in the project details. I'm a rebel like that, plus I have a Mac with an M1 processor, so it's kinda difficult to use MS SQL Server's IDE. ☹️ So Azure Data Studio looks pretty awesome.

Make sure to download both Azure Data Studio and Docker and do any tutorials they provide in their documentation, as they are both pretty good.

Setup PostgreSQL Docker Image

Pull Postgres’s docker image from CLI, but I did not install at root.

docker pull postgres

Run the container and set the port for local connecting.

docker run --name postgres-docker -e POSTGRES_PASSWORD=super_secret_password -p 5432:5432 -d postgres

The container has been made! Make sure to run it, by clicking the play button under the Actions section.

Setup Azure Data Studio

Choose the extension’s icon and search for Postgres, then install it.

Make a new Connection.

  • Connection type: PostgreSQL

  • Server name: localhost

  • User name: postgre

  • Password: super_secret_password

Then click the "Advanced..." button to add properties for connected to your database:

  • Host IP address: 0.0.0.0

  • Port: 5432

Then click OK and then Connect.

Now, you are connected to your new Docker-containerized PostgreSQL database and can do all the things in Azure Data Studio! 🙌

Â