Skip to content

Instantly share code, notes, and snippets.

@thiagoeh
Last active May 2, 2018 18:17
Show Gist options
  • Save thiagoeh/6ef0807c70ca3e2b686e6f03ab7a7eec to your computer and use it in GitHub Desktop.
Save thiagoeh/6ef0807c70ca3e2b686e6f03ab7a7eec to your computer and use it in GitHub Desktop.
Running pgexercises in a container

A dedicated container for running a PostgreSQL instance for PGexercises

PostgreSQL Exercises provides exercises for learning SQL, using a Postgres instance. This is a reference on how to setup a dedicated environment using a Docker container.

Running the container

The official Docker image for Postgres will be used. Data is persisted in a named volume PGEXERCISES, mapped to the default path inside the container. We aren't defining a password, as the connection will be local (from inside the container).

docker run --rm --name pgexercises -v PGEXERCISES:/var/lib/postgresql/data -d postgres

The container will run as root, but this is a non-issue in a learning environment.with

Running a shell inside the container

docker exec -it pgexercises bash # you will be 'inside' the container after this

To interact with Postgres

psql -U postgres 

Importing the schema (run this from inside the container)

wget https://pgexercises.com/dbfiles/clubdata.sql
psql -U postgres --file clubdata.sql
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment