Spin up local PostgreSQL instances in seconds with preloaded sample data.
-
Clone the repository:
git clone https://github.com/zseta/postgres-docker-samples.git -
Modify the
.envfile (or leave it as is):# choose a schema (must be the name of a folder) SAMPLE_SCHEMA=stocks # add database credentials POSTGRES_PORT=5432 POSTGRES_USER=postgres POSTGRES_PASSWORD=password POSTGRES_DB=example # image tag DOCKER_IMAGE_TAG=sample-db -
Build the image:
chmod +x build.sh ./build.sh -
Run the container:
chmod +x run.sh ./run.sh -
Find the connection information in the
connect.txtfile for easy copy-paste:host=localhost port=5432 database=example user=postgres password=password string=postgresql://postgres:password@localhost:5432/example
To stop the container you can press CTRL+C.
You are welcome to add new sample data folders to the project. Here's how to do it:
You need to provide two types of files: data file (in CSV format) and a schema file, in the following directory structure:
├── <new_data_folder>
│ ├── data
│ │ ├── <data_file1>.csv
│ │ └── <data_file2>.csv
│ └── schema.sqlYou can have as many CSV files in the data folder as you'd like. The content of each CSV file will be inserted into its corresponding table.
CSV file requirements:
- includes header
- the name of the file must be the same as the table defined in the schema file
- order of columns must be the same as defined in the schema file
For examples, look at any of the existing samples.