Install PostgreSQL in Docker

Run the command in terminal to install PostgreSQL in Docker:

docker run --name postgres -e POSTGRES_DB=vapor \
  -e POSTGRES_USER=vapor -e POSTGRES_PASSWORD=password \
  -p 5432:5432 -d postgres

Here’s what this does:

• Run a new container named postgres.

• Specify the database name, username and password through environment variables.

• Allow applications to connect to the Postgres server on its default port: 5432.

• Run the server in the background as a daemon.

• Use the Docker image named postgres for this container. If the image is not present on your machine, Docker automatically downloads it.


Docker then downloads all the dependencies and installs them in the current container.


To check that your database is running, enter the following in Terminal to list all active containers:


docker ps

Disclaimer: this information was taken from a book on Vapor :

Server Side Swift with Vapor

(book is amazing, buy it, I did)


Prev: Install Docker

Next: Add PostgreSQL into Vapor App


Vapor 3 Tutorial Start



#pub #postgresql #docker #db