Skip to content

Instantly share code, notes, and snippets.

@mariocesar
Last active August 24, 2018 19:33
Show Gist options
  • Save mariocesar/d02a99fe4cb74e53f35a to your computer and use it in GitHub Desktop.
Save mariocesar/d02a99fe4cb74e53f35a to your computer and use it in GitHub Desktop.
Useful docker containers

PostgreSQL

Creating a postgresql 9.5 container with persistent database

docker volume create pgdata
docker run --detach \
  --volume pgdata:/var/lib/postgresql/data \
  --name postgres \
  --env POSTGRES_PASSWORD=postgres \
  -p 5432:5432 \
  postgres:9.5
docker stop postgres
docker start postgres

Adding postgis support, create the following Dockerfile

FROM postgres:9.5
MAINTAINER Mario César Señoranis Ayala <[email protected]>

RUN apt-get update \
	&& apt-get install -y --no-install-recommends \
		postgis postgresql-9.5-postgis-2.2 \
	&& rm -rf /var/lib/apt/lists/*

Then you build and create a container, I'm using a different port so both containers above and bellow can run together

docker volume create --name postgisdata
docker build --tag postgres_postgis:9.5 .
docker run --detach \
  --volume postgisdata:/var/lib/postgresql/data \
  --name postgres_postgis \
  --env POSTGRES_PASSWORD=postgres \
  -p 5433:5432 \
  postgres_postgis:9.5

You can later install postgis in the default template to easy:

psql -U postgres -h localhost -d template1
CREATE EXTENSION postgis;
CREATE EXTENSION postgis_topology;
CREATE EXTENSION fuzzystrmatch;
CREATE EXTENSION postgis_tiger_geocoder;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment