Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is PostGIS missing? #1542

Closed
ndq1 opened this issue Apr 18, 2019 · 13 comments
Closed

Is PostGIS missing? #1542

ndq1 opened this issue Apr 18, 2019 · 13 comments

Comments

@ndq1
Copy link

ndq1 commented Apr 18, 2019

Hi,

I'm new to docker so I apologise in advance if I'm explaining myself bad.

I noticed that postGIS isn't part of the postgres container when I run

CREATE EXTENSION postgis;

I get the following error

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

Shouldn't postGIS be part of this? If not, how should it be added to the container?

It would be nice to have some way to list in the yaml file that postgis (or in general other extensions of postgres) to be loaded when the container gets set up.

Thanks for your time

@rfay
Copy link
Member

rfay commented Apr 18, 2019

ddev has no postgres container and has never supported postgres, although the php-postgres extension is in there for those using postgres externally.

Maybe you can give more information about your environment. Are you using Postgres? How?

@ndq1
Copy link
Author

ndq1 commented Apr 18, 2019

Ok, thanks for the explanation.

I am using this config.yaml

APIVersion: v1.6.0
name: my-project
type: php
docroot: web
php_version: "7.2"
webserver_type: nginx-fpm
router_http_port: "80"
router_https_port: "443"
xdebug_enabled: true
additional_hostnames: []
additional_fqdns: []
mariadb_version: "10.2"
webcache_enabled: false
nfs_mount_enabled: false
provider: default

webimage: dacostafilipe/ddev-webserver:master-pgsql

and additionally docker-compose-postges.yaml

version: '3.6'
services:
  postgres:
    container_name: ddev-${DDEV_SITENAME}-postgres
    image: postgres:11.2
    ports:
      - 32774:5432
    environment:
      - POSTGRES_PASSWORD=db
      - POSTGRES_USER=db
      - POSTGRES_DB=db
    labels:
      com.ddev.site-name: ${DDEV_SITENAME}
      com.ddev.approot: $DDEV_APPROOT
      com.ddev.app-url: $DDEV_URL
  web:
    links:
      - postgres:postgres

@rfay
Copy link
Member

rfay commented Apr 18, 2019

Thanks - when you get this the way you like it it would be great to have a writeup about it.

Now, is the problem you're having in the postgres container? If so, you'll need to solve it there. (it's https://hub.docker.com/_/postgres - you either have to derive from it, add to it, or whatever).

@rfay
Copy link
Member

rfay commented Apr 18, 2019

Oh also... you'll want to use a docker volume for the postgres database storage, otherwise it will be destroyed every time you ddev rm.

@ndq1
Copy link
Author

ndq1 commented Apr 18, 2019

I first tried to use https://hub.docker.com/r/mdillon/postgis/ but then I noticed that somehow the php-postgres extension wasn't installed so I tried https://github.com/drud/ddev/tree/master/containers/ddev-webserver. But then the postgis wasn't available.

If I understand correctly now I assume that the postgres container is missing postgis. Normally I would connect to the server and run apt-get install postgis. But I was told that when using docker I shouldn't meddle in with the container like that since it will make the container 'unhealhty'.

Thank you very much for the hint about docker volume. I will make the needed changes.

@rfay
Copy link
Member

rfay commented Apr 18, 2019

You can use ddev ssh -s postgres I would imagine and do your apt-get install, but it will be lost when you ddev rm. You may want to outfit your own container, using FROM: postgres:11.2 and then adding the things you need, then pushing to dockerhub.

@ndq1
Copy link
Author

ndq1 commented Apr 19, 2019

Thanks a lot for your help and support. I will try to make it work and reply here if there's anything new.

@ndq1
Copy link
Author

ndq1 commented Apr 19, 2019

I got it working now. All thanks to @rfay.

I used ddev to create the docker environment with

ddev config

This will create a config.yaml file in the .ddev folder. Then I added the following line to the file

webimage: dacostafilipe/ddev-webserver:master-pgsql
webimage: drud/ddev-webserver:feature-pgsql-support

This is currently needed since the php-postgres extension isn't available in the official branch, yet.

Then I created a file docker-compose-postgres.yaml in the .ddev folder

version: '3.6'
services:
  postgres:
    container_name: ddev-${DDEV_SITENAME}-postgres
    image: mdillon/postgis
    volumes:
      - type: "volume"
        source: postgresdb-database
        target: "/var/lib/postgresql"
        volume:
          nocopy: true
    ports:
      - 32774:5432
    environment:
      - POSTGRES_PASSWORD=db
      - POSTGRES_USER=db
      - POSTGRES_DB=db
    labels:
      com.ddev.site-name: ${DDEV_SITENAME}
      com.ddev.approot: $DDEV_APPROOT
      com.ddev.app-url: $DDEV_URL
  web:
    links:
      - postgres:postgres

volumes:
  postgresdb-database:
    name: "${DDEV_SITENAME}-postgresdb"

Like @rfay suggested I added a volume. I also used the mdillon/postgis image since it already contains postgis and is based on the official postgres image.

I hope this all is the correct way to do.

Again, thanks a lot for the friendly support of @rfay !

@rfay
Copy link
Member

rfay commented Apr 19, 2019

Just an FYI, because you're using dacostafilipe/ddev-webserver:master-pgsql, you're counting on that being updated as ddev gets updated, and you're depending on dacostafilipe. I'd sure like to see a more general and robust long-term solution to this. We're generally happy to add modest packages to the ddev-webserver container if they don't bloat it too much.

@ndq1
Copy link
Author

ndq1 commented Apr 19, 2019

Yes, I understand that normally using not official branches isn't the way to go. But since I saw that his branch had been merged into the drud:master branch (#1514) I assumed that it would be safe to use.

If you want I can update my solution as soon as it's available in dockerhub.

@rfay
Copy link
Member

rfay commented Apr 19, 2019

Ah, OK - That PR was pulled for the next release, #1514

So you'd be better to do this in your config.yaml until the next release, not introducing it in docker-compose.yaml:

webimage: drud/ddev-webserver:feature-pgsql-support

@ndq1
Copy link
Author

ndq1 commented Apr 23, 2019

Yes, that's the better solution. I will update my writeup above and close this ticket then.

@ndq1 ndq1 closed this as completed Apr 23, 2019
@rfay
Copy link
Member

rfay commented Apr 23, 2019

Glad it's working! In the next release, coming in May, the webimage workaround won't be required.

Thanks for the report back. If there were lots of call for it we'd probably eventually explicitly support postgres.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants