Serving Your Own OpenStreetMap Tiles with Portainer
Want to take control of your map data? This guide will walk you through setting up your very own OpenStreetMap tile server using Docker and Portainer. We'll leverage the excellent overv/openstreetmap-tile-server Docker image, and you'll have the flexibility to choose between using Docker volumes or mounting a host folder for your map data.
Prerequisites
- Docker and Portainer: Ensure you have Docker installed and Portainer running on your server.
- OpenStreetMap Data: Download an OSM data file (
.osm.pbfformat) for your desired region from a provider like Geofabrik. - Server Access: You'll need access to your server's Portainer interface and potentially the command line.
Method 1: Using a Docker Volume for Data Persistence
This method is great for keeping your Docker environment clean and self-contained. The data is managed by Docker itself.
Step 1: Create the Data Volume
- In Portainer, navigate to Volumes in the left menu.
- Click the + Add volume button.
- Enter
osm-dataas the Name. - Click Create the volume.
Step 2: Import the Map Data
- Go to Containers and click + Add container.
- Name:
osm-importer(this is temporary). - Image:
overv/openstreetmap-tile-server:latest. - Volumes: Click map additional volume twice.
- Map 1 (Bind Mount - for the .pbf file):
- Type: Bind
- Host path: (Replace with the absolute path to your
.osm.pbffile, e.g.,/srv/data/zambia-latest.osm.pbf) - Container path:
/data/region.osm.pbf
- Map 2 (Named Volume - for the database):
- Type: Volume
- Volume: Select the
osm-datavolume you created. - Container path:
/data/database/
- Map 1 (Bind Mount - for the .pbf file):
- Under the Command & logging tab, in the Command field, enter
import. - Click Deploy the container.
- Monitor the container logs until you see
INFO:root: Import complete. Once done, you can stop and remove theosm-importercontainer.
Step 3: Run the Tile Server
- Go to Containers and click + Add container.
- Name:
osm-tile-server. - Image:
overv/openstreetmap-tile-server:latest. - Ports: Click publish a new network port.
- Host:
8080(or an available port). - Container:
80.
- Host:
- Volumes: Click map additional volume.
- Type: Volume
- Volume: Select the
osm-datavolume. - Container path:
/data/database/
- Under the Command & logging tab, in the Command field, enter
run. - Under the Restart policy tab, set it to Unless stopped.
- Click Deploy the container.
Method 2: Using a Host Folder (Bind Mount) for Data
This method is useful if you want direct access to the database files on your server for backups or inspection.
Prerequisites (for Host Folder Method)
- Ensure you have an empty folder on your server where the map database will be stored (e.g.,
/srv/data/osm-database).
Step 1: Import the Map Data
- Go to Containers and click + Add container.
- Name:
osm-importer(temporary). - Image:
overv/openstreetmap-tile-server:latest. - Volumes: Click map additional volume twice.
- Map 1 (Bind Mount - for the .pbf file):
- Type: Bind
- Host path: (Replace with the absolute path to your
.osm.pbffile, e.g.,/srv/data/zambia-latest.osm.pbf) - Container path:
/data/region.osm.pbf
- Map 2 (Bind Mount - for the database folder):
- Type: Bind
- Host path: (Replace with the absolute path to your empty database folder, e.g.,
/srv/data/osm-database) - Container path:
/data/database/
- Map 1 (Bind Mount - for the .pbf file):
- Under the Command & logging tab, in the Command field, enter
import. - Click Deploy the container.
- Monitor the container logs until you see
INFO:root: Import complete. Once done, you can stop and remove theosm-importercontainer.
Step 2: Run the Tile Server
- Go to Containers and click + Add container.
- Name:
osm-tile-server. - Image:
overv/openstreetmap-tile-server:latest. - Ports: Click publish a new network port.
- Host:
8080(or an available port). - Container:
80.
- Host:
- Volumes: Click map additional volume.
- Type: Bind
- Host path: (Replace with the absolute path to your database folder, e.g.,
/srv/data/osm-database) - Container path:
/data/database/
- Under the Command & logging tab, in the Command field, enter
run. - Under the Restart policy tab, set it to Unless stopped.
- Click Deploy the container.
Verification and Troubleshooting
Verify Your Setup
Whichever method you chose, you can verify it's working by opening your web browser and navigating to:
http://<your-server-ip>:8080/tile/0/0/0.png(You should see a map image of the world)http://<your-server-ip>:8080(You should see a fully interactive map)
Troubleshooting Tips
- Permissions: If using a bind mount, ensure Docker has the necessary read/write permissions for your host folders.
- Disk Space: Creating the tile database can require significant disk space (30GB+ for even small extracts).
- Import Errors: If the import fails, you must delete the data and start over. For Method 1, delete the
osm-dataDocker volume. For Method 2, delete the contents of your host database folder. Check the container logs for clues.
Congratulations! You've now set up your own OpenStreetMap tile server using Portainer. You can further explore the overv/openstreetmap-tile-server image documentation for more advanced configuration options.
Comments
Post a Comment