Skip to content
This is a very basic example of how to run Postgres inside a Docker container
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
scripts
.env
README.md

README.md

Simple Dockerised Postgres instance

Purpose

I made this project as part of a very basic tutorial on how to run Postgres inside a Docker container.

Database setup is achieved using a script that is first passed into the Postgres container using a volume.

NOTE: this project has only been tested on OSX.

Instructions

Run the container

Navigate to the project root, and start the container with the following command:

docker run --name hackerbox-postgres-test -v $(pwd)/scripts:/scripts --env-file ./.env -p 5432:5432 -d postgres:11.1

Run the setup script:

docker exec hackerbox-postgres-test bash -c 'psql -U postgres -f ./scripts/setup.psql'

Check that the data is present

Connect to the container:

docker exec -it hackerbox-postgres-test bash

Connect to the database:

\c hackerbox_test_db

NOTE: you should receive a verification similar to the following:

You are now connected to database "hackerbox_test_db" as user "postgres".

Query the people table:

select * from people;

You should now see the contents of the people table:

 id | forename | surname
----+----------+---------
  1 | Alan     | Turing
(1 row)

Additional info

The database name and password are set in the .env file, so have a look in there before you attempt to connect to the running container externally.

You can’t perform that action at this time.