18

I created a database with docker using the postgres image as usual

docker run -d \       
--name some-postgres \
-e POSTGRES_PASSWORD=mypassword \
-v ${HOME}/postgres-data/:/var/lib/postgresql/data \
-p 5432:5432 \
postgres

now I decided to add a new column in one of the tables to store coordinates using postgis, however when I do

CREATE EXTENSION postgis;

or something similar I get this error message:

ERROR:  could not open extension control file "/usr/share/postgresql/12/extension/postgis.control": No such file or directory

is there an additional step one has to take before running the docker container in order to install postgis?

thanks a lot

DatGuy
  • 377
  • 1
  • 4
  • 10

2 Answers2

22

The postgis extension does not come with vanilla postgres, which does ship with a whole bunch of more general purpose extensions, though nothing notable for geospatial. Take a look at this instead: https://registry.hub.docker.com/r/postgis/postgis/

w08r
  • 1,639
  • 13
  • 14
  • 2
    Thanks, this helped. Actually I just needed to run the same command, but using the postgis image and mount the same volume I was using in the vanilla postgres `docker run -d \ --name some-other-postgres \ -e POSTGRES_PASSWORD=mypassword \ -v ${HOME}/postgres-data/:/var/lib/postgresql/data \ -p 5432:5432 \ postgis/postgis` – DatGuy Sep 01 '20 at 20:36
12

I know that there is already a response but this could help someone

  1. Firstly you should already have a Postgres image and after a postgres docker container running .

link 2

  1. After you should have the POSTGIS DOCKER IMAGE

[voir ici] : https://hub.docker.com/r/kartoza/postgis/

  1. The image below shows my config after all these steps

link here

  1. After you should stop the running container of postgres which was running at port 5432 for me

this could help: https://blog.eduonix.com/software-development/learn-stop-kill-clean-docker-containers/#:~:text=To%20stop%20a%20container%20you,the%20killing%20is%2010%20seconds.

  1. Now we can create the container that is going to link our postgres container with our postgis Extension
sudo docker run -d --name postgis_postgres -e POSTGRES_PASSWORD=postgrespassword -e POSTGRES_USER=postgres  -v /home/judith/Documents/postgres/db-data/:/var/lib/postgresql/data  -p 8000:8000  kartoza/postgis:9.6-2.4

Here /home/judith/Documents/postgres/db-data/ is the path to the database data of postgres container

result of this step here

  1. Now we can enter in the running container created at the step 5 with the command
judith@jlas:~$ sudo docker exec -it postgis_postgres bash
root@544c89fadeda:/# //you will be there 
  1. Write the command that is going to link to the postgres console admin , here the 5432 is port where my postgres container was running and postgres is the admin of my postgres in my config , you will config the database admin in the step 1 do not worry .
root@544c89fadeda:/# psql -h localhost -p 5432 -U postgres

you can see the result here

  1. After you can create you POSTGIS EXTENSION
postgres=# CREATE EXTENSION postgis;
CREATE EXTENSION
postgres=#
fedorqui
  • 275,237
  • 103
  • 548
  • 598