Coder Social home page Coder Social logo

docker-qgis-server's Introduction

QGIS Server for Docker

A simple docker container that runs QGIS Server

This image uses the QGIS Desktop docker image as its base.

Note You should revise the security etc. of this implementation before using in a production environment.

QGIS Server documentation

Please see the canonical documentation for QGIS Server if you need more general info on how QGIS Server works.

License

GPL V2

Usage

To use the image, either pull the latest trusted build from https://registry.hub.docker.com/u/kartoza/qgis-server/ by doing this:

docker pull kartoza/qgis-server:LTR

Note that the LTR build will always track the most recent QGIS Long Term Release build.

We use versioned images and highly recommend that you track a specific version for your orchestrated services since things may break between versions.

In this repository you will find a subdirectory for each QGIS version supported. Each directory contains a self contained docker project and we will maintain all the versioned builds from these containers.

You can build the image yourself like this:

git clone git://github.com/kartoza/docker-qgis-server
cd docker-qgis-server/2.18
docker build -t kartoza/qgis-server .

To run a container do:

docker run --name "qgis-server" -p 8080:80 -d -t kartoza/qgis-server

http://localhost:8080 should show QGIS Server, with an error because it couldn't find a QGIS project to parse.

NOTE: Again we would like to recommend you run a tagged version rather than just the latest since your configuration may break if we change something.

If you have a single QGIS project on your host to publish, you can use this command:

docker run --name "qgis-server" -v /path/to/your/project_folder/:/project -p 8080:80 -d -t kartoza/qgis-server:LTR

# Use the default test project provided by this repository in the project folder:
docker run --name "qgis-server" -v $(PWD)/project/:/project -p 8080:80 -d -t kartoza/qgis-server:LTR

The container will try to load the project located in /project called project.qgs. You can override this setting using environment variable, see below about apache configuration. http://localhost:8080 should show QGIS Server with your correct project. http://localhost:8080/?SERVICE=WMS&VERSION=1.3.0&REQUEST=GetCapabilities should give the GetCapabilities.

However, if you have many QGIS projects, you need to give the path to the project in the URL: We mount our project folder in /gis in this example to show that the name is not important.

Be careful: you need to set the environment variable QGIS_PROJECT_FILE to none, as your project won't be found under /project/project.qgs.

docker run --name "qgis-server" -e QGIS_PROJECT_FILE='' -v /path/to/your/project_folder:/gis -p 8080:80 -d -t kartoza/qgis-server:LTR

# Use the default test project provided by this repository in the project folder:
docker run --name "qgis-server" -e QGIS_PROJECT_FILE='' -v $(PWD)/project/:/gis -p 8080:80 -d -t kartoza/qgis-server:LTR

http://localhost:8080/?SERVICE=WMS&VERSION=1.3.0&REQUEST=GetCapabilities&MAP=/gis/project.qgs should give the GetCapabilities.

Example use with docker compose

Here is a contrived example showing how you can run QGIS Server from in a docker container using docker-compose. Example docker-compose follows:

db:
  image: kartoza/postgis:9.6-2.4
  environment:
    - USERNAME=docker
    - PASS=docker

qgisserver:
  image: kartoza/qgis-server:LTR
  hostname: qgis-server
  volumes:
    # Wherever you want to mount your data from
    - ./project:/project
  links:
    - db:db
  ports:
    - "8080:80"

To run the example do:

docker-compose up

You should see QGIS server start up. For more detailed approaches to using and building the QGIS Server container, see below.

http://localhost:8080 should show QGIS Server.

Note: The database in the above example is stateless (it will be deleted when running docker-compose rm). If you want to connect to the PG database from docker use the following info:

  • host: db
  • database: gis
  • user: docker
  • password: docker

Please see the provided docker-compose example which includes examples for both QGIS Server 2/LTR and QGIS Server 3.

Apache environment variables

Apache will make of the following environment variables. You can tweak these by replacing these options in your docker-compose.yml or docker run command.

APACHE_CONFDIR /etc/apache2
APACHE_ENVVARS $APACHE_CONFDIR/envvars
APACHE_RUN_USER www-data
APACHE_RUN_GROUP www-data
APACHE_RUN_DIR /var/run/apache2
APACHE_PID_FILE $APACHE_RUN_DIR/apache2.pid
APACHE_LOCK_DIR /var/lock/apache2
APACHE_LOG_DIR /var/log/apache2
LANG C

The following variables (with defaults shown) are QGIS specific options you can tweak by replacing these options in your docker-compose.yml or docker run command.

QGIS_DEBUG 5
QGIS_LOG_FILE /proc/self/fd/1
QGIS_SERVER_LOG_FILE /proc/self/fd/1
QGIS_SERVER_LOG_LEVEL 5
PGSERVICEFILE /project/pg_service.conf
QGIS_PROJECT_FILE /project/project.qgs
QGIS_PLUGINPATH /opt/qgis-server/plugins

Note: please consult the QGIS Server documentation for details on the options you can pass to QGIS Server.

Probably you will want to mount the /project folder with local volume that contains some QGIS projects. As you can see above, if no project file is specified, QGIS will try to serve up /project/project.qgs by default so if you are looking for an easy to share WMS/WFS url, simply call your project file project.qgs and mount it in the /project directory.

./build.sh; docker kill server; docker rm server;
docker run --name="qgis-server" \
    -d -p 8080:80 \
    kartoza/qgis-server:LTR
 docker logs qgis-server

Replace <path_to_local_qgis_project_folder> with an absolute path on your filesystem. That folder should contain the .qgs project files you want to publish and all the data should be relative to the project files and within the mounted volume. See https://github.com/kartoza/maps.kartoza.com for an example of a project layout that we use to power http://maps.kartoza.com

An example project folder is provided here for convenience (and we use it for validation testing).

Accessing the services:

Simply entering the URL of the docker container with its port number will respond with a valid OGC response if you use this url in QGIS 'add WMS layer' dialog.

http://localhost:8080 should show QGIS Server.

Extending and modifying Apache conf

The container uses Apache as web frontend by default (out of the box). We provided default configuration for running QGIS Server as a standalone container immediately. For production usage, or different use case, you might want to extend or change the conf file.

You can do so by providing the conf file into the container, either by extending the base image and committing a conf file in the image, or just volume mount the conf file via docker-compose. Either way, specify your new conf file location in an environment variable called QGIS_CONF_FILE. The entrypoint script then will locate your conf file and activates it by putting the link to /etc/apache2/conf-enabled folder.

If you don't need this kind of behaviour when extending the image, simply dump all of your config file into /etc/apache2/conf-enabled directory in the container. Then turn off the entrypoint script. Regular Docker common sense applies.

As our special use case, we also provide built in conf file in /etc/apache2/conf-available/qgis-single-worker. This is intended to make Apache work in single thread worker only, because the scaling is handled by container management such as Rancher/Kubernetes. This conf file might not be optimized for general use case (it will be slow if deployed as one container only).

Included QGIS Server plugins

QGIS Server supports server-side plugins written in python. The following plugins are shipped by default with this image:

  • On-the-fly project creation: This new service parameter will create a QGIS project using one or many layers existing on the file system. See the project README for details.

Authors:

Tim Sutton ([email protected]) - May 2014

Acknowledgement:

During the Girona QGIS hackfest in 2016, Patrick Valsecchi did an almost complete re-write of this image recipe which I have heavily based this and the recipe in docker-qgis-desktop on. Thanks Patrick!

docker-qgis-server's People

Contributors

gustry avatar jancelin avatar lucernae avatar rduivenvoorde avatar timlinux avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

docker-qgis-server's Issues

Add CORS by default in apache.conf

Hi,

Thank you very much for your work.

Is it ok to add "Header set Access-Control-Allow-Origin "*" " by default in in the apache conf ?
I can't request my WFS server from a client api like openlayers without CORS.

Thanks in advance

How do I update image to current 3.16?

Hi. Just wondering if there is a 3.16 image I can use for this.

Also I'm assuming I just point desktop 3.16 to the localhost 8081 port to connect right? Thanks!

QGIS Server vs ( LTR e 3.0) is not working with layers coming from the PostGis

I have run a docker qgis server instance, everything works fine with shapefiles, but when I load layers to Qgis Desktop from PostGis installed in the host and also in a docker container, the getCapabilities are not showing the layers.

I am running an Ubuntu 20.04 LTS host and Qgis Coruña. The containers were created based on the configuration bellow:

Example QGIS Server docker compose

This file will run two QGIS Server instances

QGIS 2.18 LTR - on port 8080 publishing contents of /project

QGIS 3.0 - on port 8081 publishing contents of /project-qgis3

Please read the accompanying README for more details.

db:
image: kartoza/postgis:9.6-2.4
#volumes:
#- ./pg/postgres_data:/var/lib/postgresql
environment:
- USERNAME=docker
- PASS=docker
ports:
- "5433:5432"

qgisserver3:
#build : 3,0
image: kartoza/qgis-server:3.0.3
hostname: qgis-server
environment:
# set to '' if you plan on hosting
# multiple projects on this server an
# then add map= to your GET
# requests
- QGIS_PROJECT_FILE=''
# 0 = highest level, shows all messages
# 5 = very quiet
- QGIS_SERVER_LOG_LEVEL=0
volumes:
- /home/geo/Documents/qgis/projects:/project
ports:
- "80:80"
links:
- db:db

I can't run docker-qgis-server container

Sorry I'm a newsbee in docker but I can't run your docker-qgis-server container.

docker run --name "qgis-server" -p 2222:22 -p 8080:80 -d -t kartoza/docker-qgis-server
7109debdbfe9fa698df41c3e15584a496116a1325e539388a52b4e6b47d541aa
2014/08/27 17:21:54 Error: Cannot start container 7109debdbfe9fa698df41c3e15584a496116a1325e539388a52b4e6b47d541aa: port has already been allocated

and if I change port docker create a container but his statut is exited:

docker run --name "qgis-server" -p 2222:22 -p 8081:80 -d -t kartoza/docker-qgis-server
docker ps -a
CONTAINER ID        IMAGE                               COMMAND                CREATED             STATUS                     PORTS                    NAMES
75a6e3c0d7c6        kartoza/docker-qgis-server:latest   /bin/sh -c 'apachect   3 seconds ago       Exited (1) 2 seconds ago                            qgis-server  

For exemple I have docker ui and It works fine:

CONTAINER ID        IMAGE                               COMMAND                CREATED             STATUS                     PORTS                    NAMES
75a6e3c0d7c6        kartoza/docker-qgis-server:latest   /bin/sh -c 'apachect   3 seconds ago       Exited (1) 2 seconds ago                            qgis-server         
5835fa3b861b        crosbymichael/dockerui:latest       ./dockerui -e /docke   7 weeks ago         Up 21 minutes              0.0.0.0:8001->9000/tcp   evil_brown 

Error building image

When I try to build the image i get the following error:

Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
qgis-mapserver : Depends: qgis-providers (= 2.4.0+wheezy1) but it is not going to be installed
Depends: libgdal1 (>= 1.8.0) but it is not installable
Depends: libqgis-analysis2.4.0 but it is not going to be installed
Depends: libqgis-core2.4.0 but it is not going to be installed
Depends: libspatialindex1 but it is not installable

server configuration error

This image does not work. Tried with the default project, copying my own into the container, and use a volume reference.

> <ServiceExceptionReport xmlns="http://www.opengis.net/ogc" version="1.3.0">
> <ServiceException code="Service configuration error">Service unknown or unsupported</ServiceException>
> </ServiceExceptionReport>``

ServiceException code="InvalidCRS" (qgis-server:3.0.3)

After switching from kartoza/qgis-server:2.18 to kartoza/qgis-server:3.0.3 I encounter various issues.
Besides #17, the GetMap requests now respond with error code 400:

<ServiceExceptionReport xmlns="http://www.opengis.net/ogc" version="1.3.0">
 <ServiceException code="InvalidCRS">Could not create output CRS</ServiceException>
</ServiceExceptionReport>

This might be caused by some path/config issue, as the log indicates some database access issues(?):

...
[84][12:42:10] Can't open database: unable to open database file
[84][12:42:10] Can't open database: unable to open database file
[84][12:42:10] Can't open database: unable to open database file
[84][12:42:11] Error, could not create output CRS from EPSG

QGIS server is not working with layers coming from the database

Problem

I have my compose file setup

postgres:
  image: kartoza/postgis:9.5-2.2
  ports:
    - "35432:5432"
  environment:
    - USERNAME=docker
    - PASS=docker
qgisserver:
  image: kartoza/qgis-server:2.18.10
  hostname: qgis-server
  volumes:
    - ./web:/web
  environment:
    - QGIS_PROJECT_FILE=/web/project/project.qgs
    - PGSERVICEFILE=/web/project/pg_service.conf
  links:
    - postgres:postgres
  ports:
    - "30003:80"

When I log into the qgis-server container I can connect to the Postgres container by using the service file. psql service=gis but when I do a get capabilities on my layer the request generated is not valid.
get

I then proceed to open the project file and replace my data source with a shapefile and do a get capabilities which returns true.

I think QGIS server is not connecting properly to the Postgres container.

QGIS Server Crashing with memory leak on Huge GeoJSON layer.

Problem

Due to the recent crash as described here: kartoza/geosafe#538 ,
we found out that on a GeoJSON layer with big size (something like 60MB in test case), the memory usage rocket into 2GB to process these layers. Moreover, when it crash, apache doesn't release the resources, so it has memory leak.

Proposed Solutions

When processing huge GeoJSON layer like this, we might have to disable multiprocess thread.
Let's say the map client requested 4 tiles in parallel. Usually one QGIS Server instance might take all these request and handle it by forking the process in a different thread/worker. But for this case, it causes these problem:

  1. All thread work with a different memory page (not shared), so for 60 MB GeoJSON file in test case, it ends up with 4x2GB memory consumptions.
  2. When the thread crash, the memory leak stays there, it's not being cleaned up.
  3. all 4 thread will try to access the same resource and race condition happens (because it was not quick enough to process tiles).

So I suggest the following solutions:

  1. Gave an option to use a separate apache config file where scaling is handled at the container level (scaling the instance, not apache thread)
  2. In this config, we only uses maximum of 1 worker (no race condition will happen in that container)
  3. In this config, we will not use keep alive. We want to close the connection and make the worker restart fresh to avoid memory leak.

CC @timlinux

QGIS Server 3

Is is likely this process will work for QGIS Server 3?

I can set up a PR, if you like. Just wanted to confirm that it will work before I get stuck in...

InvalidCRS Issue

Hi,
we are fiddling with the QGIS-Server 3 container. I have a bunch of database layers (PostGIS), all in EPSG:25832. The projct is in EPSG:25832, too. GetCapabilities lists all layers with their bounding box and tells me that EPSG:25832 is an available CRS for both the project and the individual layers. A GetMap request however returns:
<ServiceExceptionReport version="1.3.0"> <ServiceException code="InvalidCRS">Could not create output CRS</ServiceException></ServiceExceptionReport>

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.