Skip to content
master
Switch branches/tags
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 

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.

About

This is a very basic example of how to run Postgres inside a Docker container

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published