{"id":22488784,"url":"https://github.com/Overv/openstreetmap-tile-server","last_synced_at":"2025-08-02T21:31:43.380Z","repository":{"id":37470625,"uuid":"132661178","full_name":"Overv/openstreetmap-tile-server","owner":"Overv","description":"Docker file for a minimal effort OpenStreetMap tile server","archived":false,"fork":false,"pushed_at":"2024-04-20T19:03:06.000Z","size":160,"stargazers_count":1234,"open_issues_count":81,"forks_count":488,"subscribers_count":30,"default_branch":"master","last_synced_at":"2024-11-30T12:02:53.081Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Overv.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-05-08T20:28:08.000Z","updated_at":"2024-11-29T07:50:44.000Z","dependencies_parsed_at":"2024-10-29T18:09:00.363Z","dependency_job_id":null,"html_url":"https://github.com/Overv/openstreetmap-tile-server","commit_stats":null,"previous_names":[],"tags_count":32,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Overv%2Fopenstreetmap-tile-server","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Overv%2Fopenstreetmap-tile-server/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Overv%2Fopenstreetmap-tile-server/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Overv%2Fopenstreetmap-tile-server/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Overv","download_url":"https://codeload.github.com/Overv/openstreetmap-tile-server/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228500220,"owners_count":17930019,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-06T17:18:43.114Z","updated_at":"2024-12-06T17:20:46.875Z","avatar_url":"https://github.com/Overv.png","language":"Shell","funding_links":[],"categories":["Shell"],"sub_categories":[],"readme":"# openstreetmap-tile-server\n\n[![Build Status](https://travis-ci.org/Overv/openstreetmap-tile-server.svg?branch=master)](https://travis-ci.org/Overv/openstreetmap-tile-server) [![](https://images.microbadger.com/badges/image/overv/openstreetmap-tile-server.svg)](https://microbadger.com/images/overv/openstreetmap-tile-server \"openstreetmap-tile-server\")\n[![Docker Image Version (latest semver)](https://img.shields.io/docker/v/overv/openstreetmap-tile-server?label=docker%20image)](https://hub.docker.com/r/overv/openstreetmap-tile-server/tags)\n\nThis container allows you to easily set up an OpenStreetMap PNG tile server given a `.osm.pbf` file. It is based on the [latest Ubuntu 18.04 LTS guide](https://switch2osm.org/serving-tiles/manually-building-a-tile-server-18-04-lts/) from [switch2osm.org](https://switch2osm.org/) and therefore uses the default OpenStreetMap style.\n\n## Setting up the server\n\nFirst create a Docker volume to hold the PostgreSQL database that will contain the OpenStreetMap data:\n\n    docker volume create osm-data\n\nNext, download an `.osm.pbf` extract from geofabrik.de for the region that you're interested in. You can then start importing it into PostgreSQL by running a container and mounting the file as `/data/region.osm.pbf`. For example:\n\n```\ndocker run \\\n    -v /absolute/path/to/luxembourg.osm.pbf:/data/region.osm.pbf \\\n    -v osm-data:/data/database/ \\\n    overv/openstreetmap-tile-server \\\n    import\n```\n\nIf the container exits without errors, then your data has been successfully imported and you are now ready to run the tile server.\n\nNote that the import process requires an internet connection. The run process does not require an internet connection. If you want to run the openstreetmap-tile server on a computer that is isolated, you must first import on an internet connected computer, export the `osm-data` volume as a tarfile, and then restore the data volume on the target computer system.\n\nAlso when running on an isolated system, the default `index.html` from the container will not work, as it requires access to the web for the leaflet packages.\n\n### Automatic updates (optional)\n\nIf your import is an extract of the planet and has polygonal bounds associated with it, like those from [geofabrik.de](https://download.geofabrik.de/), then it is possible to set your server up for automatic updates. Make sure to reference both the OSM file and the polygon file during the `import` process to facilitate this, and also include the `UPDATES=enabled` variable:\n\n```\ndocker run \\\n    -e UPDATES=enabled \\\n    -v /absolute/path/to/luxembourg.osm.pbf:/data/region.osm.pbf \\\n    -v /absolute/path/to/luxembourg.poly:/data/region.poly \\\n    -v osm-data:/data/database/ \\\n    overv/openstreetmap-tile-server \\\n    import\n```\n\nRefer to the section *Automatic updating and tile expiry* to actually enable the updates while running the tile server.\n\nPlease note: If you're not importing the whole planet, then the `.poly` file is necessary to limit automatic updates to the relevant region.\nTherefore, when you only have a `.osm.pbf` file but not a `.poly` file, you should not enable automatic updates.\n\n### Letting the container download the file\n\nIt is also possible to let the container download files for you rather than mounting them in advance by using the `DOWNLOAD_PBF` and `DOWNLOAD_POLY` parameters:\n\n```\ndocker run \\\n    -e DOWNLOAD_PBF=https://download.geofabrik.de/europe/luxembourg-latest.osm.pbf \\\n    -e DOWNLOAD_POLY=https://download.geofabrik.de/europe/luxembourg.poly \\\n    -v osm-data:/data/database/ \\\n    overv/openstreetmap-tile-server \\\n    import\n```\n\n### Using an alternate style\n\nBy default the container will use openstreetmap-carto if it is not specified. However, you can modify the style at run-time. Be aware you need the style mounted at `run` AND `import` as the Lua script needs to be run:\n\n```\ndocker run \\\n    -e DOWNLOAD_PBF=https://download.geofabrik.de/europe/luxembourg-latest.osm.pbf \\\n    -e DOWNLOAD_POLY=https://download.geofabrik.de/europe/luxembourg.poly \\\n    -e NAME_LUA=sample.lua \\\n    -e NAME_STYLE=test.style \\\n    -e NAME_MML=project.mml \\\n    -e NAME_SQL=test.sql \\\n    -v /home/user/openstreetmap-carto-modified:/data/style/ \\\n    -v osm-data:/data/database/ \\\n    overv/openstreetmap-tile-server \\\n    import\n```\n\nIf you do not define the \"NAME_*\" variables, the script will default to those found in the openstreetmap-carto style.\n\nBe sure to mount the volume during `run` with the same `-v /home/user/openstreetmap-carto-modified:/data/style/`\n\nIf you do not see the expected style upon `run` double check your paths as the style may not have been found at the directory specified. By default, `openstreetmap-carto` will be used if a style cannot be found\n\n**Only openstreetmap-carto and styles like it, eg, ones with one lua script, one style, one mml, one SQL can be used**\n\n## Running the server\n\nRun the server like this:\n\n```\ndocker run \\\n    -p 8080:80 \\\n    -v osm-data:/data/database/ \\\n    -d overv/openstreetmap-tile-server \\\n    run\n```\n\nYour tiles will now be available at `http://localhost:8080/tile/{z}/{x}/{y}.png`. The demo map in `leaflet-demo.html` will then be available on `http://localhost:8080`. Note that it will initially take quite a bit of time to render the larger tiles for the first time.\n\n### Using Docker Compose\n\nThe `docker-compose.yml` file included with this repository shows how the aforementioned command can be used with Docker Compose to run your server.\n\n### Preserving rendered tiles\n\nTiles that have already been rendered will be stored in `/data/tiles/`. To make sure that this data survives container restarts, you should create another volume for it:\n\n```\ndocker volume create osm-tiles\ndocker run \\\n    -p 8080:80 \\\n    -v osm-data:/data/database/ \\\n    -v osm-tiles:/data/tiles/ \\\n    -d overv/openstreetmap-tile-server \\\n    run\n```\n\n**If you do this, then make sure to also run the import with the `osm-tiles` volume to make sure that caching works properly across updates!**\n\n### Enabling automatic updating (optional)\n\nGiven that you've set up your import as described in the *Automatic updates* section during server setup, you can enable the updating process by setting the `UPDATES` variable while running your server as well:\n\n```\ndocker run \\\n    -p 8080:80 \\\n    -e REPLICATION_URL=https://planet.openstreetmap.org/replication/minute/ \\\n    -e MAX_INTERVAL_SECONDS=60 \\\n    -e UPDATES=enabled \\\n    -v osm-data:/data/database/ \\\n    -v osm-tiles:/data/tiles/ \\\n    -d overv/openstreetmap-tile-server \\\n    run\n```\n\nThis will enable a background process that automatically downloads changes from the OpenStreetMap server, filters them for the relevant region polygon you specified, updates the database and finally marks the affected tiles for rerendering.\n\n### Tile expiration (optional)\n\nSpecify custom tile expiration settings to control which zoom level tiles are marked as expired when an update is performed. Tiles can be marked as expired in the cache (TOUCHFROM), but will still be served\nuntil a new tile has been rendered, or deleted from the cache (DELETEFROM), so nothing will be served until a new tile has been rendered.\n\nThe example tile expiration values below are the default values.\n\n```\ndocker run \\\n    -p 8080:80 \\\n    -e REPLICATION_URL=https://planet.openstreetmap.org/replication/minute/ \\\n    -e MAX_INTERVAL_SECONDS=60 \\\n    -e UPDATES=enabled \\\n    -e EXPIRY_MINZOOM=13 \\\n    -e EXPIRY_TOUCHFROM=13 \\\n    -e EXPIRY_DELETEFROM=19 \\\n    -e EXPIRY_MAXZOOM=20 \\\n    -v osm-data:/data/database/ \\\n    -v osm-tiles:/data/tiles/ \\\n    -d overv/openstreetmap-tile-server \\\n    run\n```\n\n### Cross-origin resource sharing\n\nTo enable the `Access-Control-Allow-Origin` header to be able to retrieve tiles from other domains, simply set the `ALLOW_CORS` variable to `enabled`:\n\n```\ndocker run \\\n    -p 8080:80 \\\n    -v osm-data:/data/database/ \\\n    -e ALLOW_CORS=enabled \\\n    -d overv/openstreetmap-tile-server \\\n    run\n```\n\n### Connecting to Postgres\n\nTo connect to the PostgreSQL database inside the container, make sure to expose port 5432:\n\n```\ndocker run \\\n    -p 8080:80 \\\n    -p 5432:5432 \\\n    -v osm-data:/data/database/ \\\n    -d overv/openstreetmap-tile-server \\\n    run\n```\n\nUse the user `renderer` and the database `gis` to connect.\n\n```\npsql -h localhost -U renderer gis\n```\n\nThe default password is `renderer`, but it can be changed using the `PGPASSWORD` environment variable:\n\n```\ndocker run \\\n    -p 8080:80 \\\n    -p 5432:5432 \\\n    -e PGPASSWORD=secret \\\n    -v osm-data:/data/database/ \\\n    -d overv/openstreetmap-tile-server \\\n    run\n```\n\n## Performance tuning and tweaking\n\nDetails for update procedure and invoked scripts can be found here [link](https://ircama.github.io/osm-carto-tutorials/updating-data/).\n\n### THREADS\n\nThe import and tile serving processes use 4 threads by default, but this number can be changed by setting the `THREADS` environment variable. For example:\n```\ndocker run \\\n    -p 8080:80 \\\n    -e THREADS=24 \\\n    -v osm-data:/data/database/ \\\n    -d overv/openstreetmap-tile-server \\\n    run\n```\n\n### CACHE\n\nThe import and tile serving processes use 800 MB RAM cache by default, but this number can be changed by option -C. For example:\n```\ndocker run \\\n    -p 8080:80 \\\n    -e \"OSM2PGSQL_EXTRA_ARGS=-C 4096\" \\\n    -v osm-data:/data/database/ \\\n    -d overv/openstreetmap-tile-server \\\n    run\n```\n\n### AUTOVACUUM\n\nThe database use the autovacuum feature by default. This behavior can be changed with `AUTOVACUUM` environment variable. For example:\n```\ndocker run \\\n    -p 8080:80 \\\n    -e AUTOVACUUM=off \\\n    -v osm-data:/data/database/ \\\n    -d overv/openstreetmap-tile-server \\\n    run\n```\n\n### FLAT_NODES\n\nIf you are planning to import the entire planet or you are running into memory errors then you may want to enable the `--flat-nodes` option for osm2pgsql. You can then use it during the import process as follows:\n\n```\ndocker run \\\n    -v /absolute/path/to/luxembourg.osm.pbf:/data/region.osm.pbf \\\n    -v osm-data:/data/database/ \\\n    -e \"FLAT_NODES=enabled\" \\\n    overv/openstreetmap-tile-server \\\n    import\n```\n\nWarning: enabling `FLAT_NOTES` together with `UPDATES` only works for entire planet imports (without a `.poly` file).  Otherwise this will break the automatic update script. This is because trimming the differential updates to the specific regions currently isn't supported when using flat nodes.\n\n### Benchmarks\n\nYou can find an example of the import performance to expect with this image on the [OpenStreetMap wiki](https://wiki.openstreetmap.org/wiki/Osm2pgsql/benchmarks#debian_9_.2F_openstreetmap-tile-server).\n\n## Troubleshooting\n\n### ERROR: could not resize shared memory segment / No space left on device\n\nIf you encounter such entries in the log, it will mean that the default shared memory limit (64 MB) is too low for the container and it should be raised:\n```\nrenderd[121]: ERROR: failed to render TILE default 2 0-3 0-3\nrenderd[121]: reason: Postgis Plugin: ERROR: could not resize shared memory segment \"/PostgreSQL.790133961\" to 12615680 bytes: ### No space left on device\n```\nTo raise it use `--shm-size` parameter. For example:\n```\ndocker run \\\n    -p 8080:80 \\\n    -v osm-data:/data/database/ \\\n    --shm-size=\"192m\" \\\n    -d overv/openstreetmap-tile-server \\\n    run\n```\nFor too high values you may notice excessive CPU load and memory usage. It might be that you will have to experimentally find the best values for yourself.\n\n### The import process unexpectedly exits\n\nYou may be running into problems with memory usage during the import. Have a look at the \"Flat nodes\" section in this README.\n\n## License\n\n```\nCopyright 2019 Alexander Overvoorde\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n    https://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FOverv%2Fopenstreetmap-tile-server","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FOverv%2Fopenstreetmap-tile-server","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FOverv%2Fopenstreetmap-tile-server/lists"}