This Docker image is designed to simplify the process of importing OpenStreetMap data into a PostgreSQL database using the osm2pgsql tool.
- Build the Docker image:
docker build -t osm2pgsql .
- Run the image:
docker run osm2pgsql
This will use the default values provided in the Dockerfile. To customize the execution, you can override the default environment variables and/or CMD.
PBF_PATH
: The path to the OSM .pbf data file inside the container. Default: /data/data.osm.pbfLUA_SCRIPT_PATH
: The path to a Lua script for custom processing. Default: /data/filter.luaPGHOST
: The host of the PostgreSQL server. Default: host.docker.internalPGUSER
: PostgreSQL user. Default: postgresPGPASSWORD
: PostgreSQL password. Default: passwordPGDATABASE
: The name of the PostgreSQL database. Default: osm_db
To use custom OSM data and Lua script, use the following command:
docker run -v $(pwd)/data:/data osm2pgsql -H host.docker.internal -U postgres -d osmberlin -O flex -S /data/filter.lua /data/berlin-latest.osm.pbf
Ensure that both berlin-latest.osm.pbf and filter.lua are located in the data directory in your current path.
- Ensure the PostgreSQL server is accessible from the Docker container. The default host host.docker.internal assumes a local PostgreSQL server when using Docker for Desktop.
- Ensure you have initialized the PostgreSQL database with the PostGIS extension to handle spatial data.
- Set the network host correctly if you're on linux:
docker run --network="host" -v $(pwd)/data:/data osm2pgsql -H localhost -U postgres -d osmberlin -O flex -S /data/filter.lua /data/berlin-latest.osm.pbf