Trying to create postgis inside docker file gives the error

Here is the command that I’m trying to run.

I’m using official postgres docker image.
I can’t find any info about ‘is not a database cluster directory’

  • Compose: running a container that exits
  • Running a Bash Script from (on Docker Container B) from Docker Container A
  • Docker volume not used with Redis (mount does show up with inspect)
  • Unable to start docker after configuring hosts in daemon.json
  • Creating multiple Docker container
  • Rails controller caching when using docker container (dev)
  • Step 7 : RUN pg_ctl start -w &&     createdb postgis_template -E UTF8 &&    psql -d postgis_template -c "create extension if not exists postgis;" &&    pg_ctl stop -w
         ---> Running in da5745cab398
        pg_ctl: directory "/var/lib/postgresql/data" is not a database cluster directory

  • How to downgrade Docker on Mac to 1.12.x or connect to 1.12 hosts from 1.13 in Mac?
  • docker volume driver: unable to override existing file
  • Run nano server container on a Raspberry PI 3
  • Error starting docker postgres on travis-
  • How to copy a file from container to host using copy in docker-py
  • Virtualhost: Put online a Flask website with Docker
  • One Solution collect form web for “Trying to create postgis inside docker file gives the error”

    You’re getting this error because there is no database cluster created inside the postgres docker image when you’re attempting to run the pg_ctl start command.

    The database cluster is created when you run a docker container based on the image, as the initdb binary is called as part of the script that is set as the ENTRYPOINT for the postgres container.

    If you’re running your postgres container with a mounted data volume that is persistent across container restarts, you can just run this command once from a psql shell, or you can override the script and add your own custom one that creates the postgis extension.

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.