Search code examples
postgresqldockerdocker-composepostgis

Docker and Postgis - How do I access shp2pgsql inside my docker container?


I am running postgres in a docker container using docker-compose and it spins up with no issue and I am able to connect to the database. But now I want to go into the container and execute the postgis shp2pgsql to load a shape file but the command seems to be nonexistent. Below is my code:

docker-compose.yaml

version: '3'

services:
  db:
    container_name: pg_container
    image: postgis/postgis
    restart: always
    environment:
      POSTGRES_USER: root
      POSTGRES_PASSWORD: root
      POSTGRES_DB: test_db
    volumes:
        - ./data:/var/lib/postgresql/
        - ./postgres_init:/postgres_init
    ports:
        - 5433:5433
    networks:
        - ch_ntw

networks:
  ch_ntw:
    driver: bridge
    ipam:
      config:
        - subnet: 10.222.1.0/24

Getting into the container:

docker exec -it pg_container bash

Connecting to the db without issue using psql:

psql --host=pg_container --dbname=test_db --username=root

But then if I try to invoke shp2pgsql from bash I get the following:

 shp2pgsql -s 2263:4326 postgres_init/nyct2010_15b/nyct2010.shp | psql -d test_db

bash: shp2pgsql: command not found

I would think since this is a postgis container that the function should be accessible no?


Solution

  • shp2pgsql is a client package. The postgis/postgis image is the PostGIS server components only. If you want to use shp2pgsql or other client tools, install them locally on your host, or in another container.