postgis / docker-postgis

Docker image for PostGIS
https://hub.docker.com/r/postgis/postgis/
MIT License
1.39k stars 466 forks source link

PostGIS CLIs don't seem to be available within the container unless explicitly installed via the OS package manager #224

Closed zachsa closed 3 years ago

zachsa commented 3 years ago

Hi,

Running the 13-3.1 Docker image:

docker run --name postgis -e POSTGRES_USER=admin -e POSTGRES_PASSWORD=password -e POSTGRES_DB=mydb -d -p 5432:5432  postgis/postgis:13-3.1

I see that it's necessary to enable extensions. Running create extension SQL on the database mydb enables the extensions successfully (I think at least):

create extension if not exists address_standardizer;
create extension if not exists address_standardizer_data_us;
create extension if not exists bloom;
create extension if not exists btree_gin;
create extension if not exists btree_gist;
create extension if not exists cube;
create extension if not exists fuzzystrmatch;
create extension if not exists intarray;
create extension if not exists pg_trgm;
create extension if not exists pgcrypto;
create extension if not exists postgis;
create extension if not exists postgis_raster;
create extension if not exists postgis_sfcgal;
create extension if not exists postgis_tiger_geocoder;
create extension if not exists postgis_topology;

The \dx commands shows that these extensions are installed and enabled:

                                                                       List of installed extensions
             Name             | Version |   Schema   |                                                     Description
------------------------------+---------+------------+---------------------------------------------------------------------------------------------------------------------
 address_standardizer         | 3.1.0   | public     | Used to parse an address into constituent elements. Generally used to support geocoding address normalization step.
 address_standardizer_data_us | 3.1.0   | public     | Address Standardizer US dataset example
 bloom                        | 1.0     | public     | bloom access method - signature file based index
 btree_gin                    | 1.3     | public     | support for indexing common datatypes in GIN
 btree_gist                   | 1.5     | public     | support for indexing common datatypes in GiST
 cube                         | 1.4     | public     | data type for multidimensional cubes
 fuzzystrmatch                | 1.1     | public     | determine similarities and distance between strings
 intarray                     | 1.3     | public     | functions, operators, and index support for 1-D arrays of integers
 pg_trgm                      | 1.5     | public     | text similarity measurement and index searching based on trigrams
 pgcrypto                     | 1.3     | public     | cryptographic functions
 plpgsql                      | 1.0     | pg_catalog | PL/pgSQL procedural language
 postgis                      | 3.1.0   | public     | PostGIS geometry and geography spatial types and functions
 postgis_raster               | 3.1.0   | public     | PostGIS raster types and functions
 postgis_sfcgal               | 3.1.0   | public     | PostGIS SFCGAL functions
 postgis_tiger_geocoder       | 3.1.0   | tiger      | PostGIS tiger geocoder and reverse geocoder
 postgis_topology             | 3.1.0   | topology   | PostGIS topology spatial types and functions

But trying to run the raster2pgsql command, it doesn't seems to exist:

docker exec -it postgis raster2pgsql
# OCI runtime exec failed: exec failed: container_linux.go:370: starting container process caused: exec: "raster2pgsql": executable file not found in $PATH: unknown

Looking inside the container

docker container exec -it postgis bash

I can't find the raster2pgsql installation. I've looked in a few places including /usr/bin, /usr/lib/postgresql/13/**/*, and a couple other places.

Once in the container I can install PostGIS manually:

apt-get update -y
apt-get install postgis -y

And now I have access to these tools.

Is this intended?

It seems strange that I should have to install PostGIS into a Docker container that is created from a PostGIS image. This is likely also the reason for this question - https://github.com/postgis/docker-postgis/issues/222 , and is possibly related to https://github.com/postgis/docker-postgis/issues/191

phillipross commented 3 years ago

That's correct, in order to keep the image size small, not everything is installed. Currently the possibility of maintaining multiple variants of the image are being explored, where some variants would be geared toward scaling out production environments while others would be better for development and testing environments. The former benefits from smaller image sizes while the later can afford to have more utilities preinstalled for convenience.

zachsa commented 3 years ago

Okay thanks.

It's quite easy to extend this docker image with my own dockerfile, and I think it would make more sense to provide an example of how to do this rather than provide more images to choose from.

phillipross commented 3 years ago

I agree 100% and acknowledge that the documentation definitely needs to improve in multiple areas. If you think you could help with this, all pull requests are welcome 😉

zachsa commented 3 years ago

I would suggest an examples folder somewhere. Each example is a directory that contains a Dockerfile and a README.md file.

For example, there could be:

https://github.com/postgis/docker-postgis/tree/master/13-master/examples/
  - README.md (with instructions on simple usage)
  - /with-raster2pgsql-cli
      - Dockerfile
      - README.md
  - /with-other-cli
     - Dockerfile
     - README.md
  - /etc

If you like this idea let me know and I will implement it.

phillipross commented 3 years ago

@zachsa that sounds great 👍

Something to be aware of: The postges image in the Docker Official Images contains information about extending the postgres image itself. They've actually put links to this docker-postgis repo there, so it might be fine to piggyback off of their documentation and probably a good idea to avoid duplicating concepts they already cover there. In some cases we've had folks create issues here with questions that were already answered by the postgres image's docs.

zachsa commented 3 years ago

Okay, thanks. I just had a quick look at the link and didn't see anything immediately obvious to me that I would need to consider. My intention is to create an EXTREMELY basic Dockerfile with the CLI's enabled as an example. This is actually useful since it looks like some people who use this image get stuck trying to use the CLIs with the basic image.

zachsa commented 3 years ago

Please let me know if this is on the right track @phillipross. I use these tools (Docker, PostGIS, etc.) in quite a simple way, so my ability to do more complex work on this is limited.

phillipross commented 3 years ago

@zachsa Thanks for PR!