After defining the basic assumptions about the project, it is time to install PostgreSQL.
If you want to install PostgreSQL directly on your machine, check out the instructions on the official PostgreSQL site.
The command on the right starts the PostgreSQL database instance inside a Docker container.
The command to run PostgreSQL instance in Docker container with the required
POSTGRES_PASSWORD environment variable, which is the superuser password, and with the
POSTGRES_DB environment variable, which is the name of the default database created when the image starts. In our project, the database name is
docker run --rm --name postgresql-intro-gosamples -p 5432:5432 -e POSTGRES_PASSWORD=mysecretpassword -e POSTGRES_DB=website postgres
The command also maps port 5432 of our container to port 5432 on our host according to the pattern:
This step is necessary to connect from our machine to the PostgreSQL located inside the container.
--rm ensures that the container will be automatically cleaned up and the file system removed when the container exits. This is a convenient option because we will be restarting the container frequently.
If PostgreSQL was started correctly, you should see a similar log message at the end of the standard output:
database system is ready to accept connections