Install PostGIS on Fedora 28 – An Applied Docker Containers for GIS

PostGIS is a spatial extension for PostgreSQL. If you own PostgreSQL Server you can use it to store your spatial databases such as polygon, polyline or points in the PostgreSQL server. By default, PostGIS is not enabled in PostgreSQL. On this tutorial, we are going to learn how to install PostGIS on Fedora 28. There are several options to install PostGIS and PostgreSQL on Fedora 28. 

  1. Install PostgreSQL and PostGIS on the Fedora host
  2. Run PostgreSQL and PostGIS container using Docker

I am not going to explain the installation on the Fedora host. There are many tutorials that explain this already. Here we will deploy a PostgreSQL server container and then install PostGIS on top of it. There are several steps we need to take in order to have a fully working PostGIS spatial database server using Docker container. 

  1. Install Docker CE on Fedora 28
  2. Run PostgreSQL container
  3. Install PostGIS
  4. Create a new database
  5. Enable PostGIS extension on existing database

Step 1. Install Docker on Fedora 28

Please follow the instruction on this page to get Docker CE up and running on Fedora 28. It’s a pretty simple tutorial that is easy to follow.

Step 2. Run PostgreSQL Container

After Docker is up and running, let’s fire up the PostgreSQL container with the following command

Change the following items with your own settings:

  • postgresql01 ==> name of the container. You can change it to anything you like
  • 12345 ==> password for postgres user.
  • 54320 ==> assigned port. The default port is 5432. I am assigning port 54320 on my Fedora host. You can either use the default port or change to something else. If you use default port, change it to 5432:5432
  • postgres ==> The image used to deploy the server. It will download the latest version from docker hub. 

When complete, check with docker ps command, and make sure our container is up and running.

So at this point, we have a working PostgreSQL Server. 

Step 3. Install PostGIS inside the PostgreSQL container

Next, we are going to install PostGIS inside the container we created on the previous step. We are going to enter the container shell. 

Depends on how you name your container, change postgresql01 with the actual container name. Now, while in the container shell, execute the update and install postgis

It will install a bunch of dependency files.

Login to PostgreSQL Server

Once installation completes, let’s continue to create a new database. Still inside the container let’s login to PostgreSQL server with user postgres.

Output:

Create a New Database

So now, we are inside the PostgreSQL console. Let’s create a new database called gis_database

Output:

Enable PostGIS Extension on a Database

Now we have a new database. Next, we need to enable the postgis extension on the new database. For your information, postgis extension needs to be enabled on every database you want to use it as a spatial database. 

First, connect to the database

Output:

Now let’s enable the postgis extension to our gis_database

Output

That’s it. Now we have a new PostGIS database called gis_database and we can start uploading our spatial datasets to this new PostGIS database. 

Ariel

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.