My Back-end Adventures — Setting up a local database (Postgres)

Setting up Docker

  • Creates 2 services (containers) for us called postgres and pgadmin
  • Sets the default username and password for us to access externally
  • Maps the corresponding ports. 5432:5432 on the postgres container means that port 5432 on the host machine is mapped to 5432 inside the docker container. The same logic applies for 5050:80 for pgadmin
  • Creates volumes for our containers. Even if our container is shut down, our data will persist. postgres:/data/postgres means the postgres folder in our local machine is mapped to the /data/postgres folder inside the docker container
  • Creates a common network called postgres so that our 2 containers can communicate with each other.

Running the Docker containers and connecting PgAdmin to Postgres

  • Host name/address is postgres. This field is asking us for the name or IP address of the machine that the Postgres database is located. Since we're using Docker, the container is considered a machine of its own with a name and address. The name is postgres as specified by our docker-compose.yml file. If we were connecting to a locally installed version of Postgres without Docker, it would have been localhost since the database would be located on your local machine.
  • Port is 5432. This is the standard Postgres port. Since both Docker container are using the same network, they can see each other's port without having to use different IP addresses
  • Maintenance Database is postgres. This is standard and should not be altered.
  • Username is postgres. This was specified as POSTGRES_USER in the docker-compose.yml file. If you changed it, then you need to specify that change in this field.
  • Password is password. This was specified as POSTGRES_PASSWORD in the docker-compose.yml file. If you changed it, then you need to specify that change in this field.

Setting up your Express server

  • express
  • pg
  • pg-hstore
  • sequelize
Listening on port 5000
Executing (default): SELECT 1+1 AS result
Database connected!

Conclusion

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Qarun Qadir Bissoondial

Qarun Qadir Bissoondial

6 Followers

Just a Software Engineer interested in Clean, Maintainable, Reusable code. Angular | CI/CD | Full Stack Web Development