如果你使用 DeepSeek、元宝 AI、Copilot、ChatGPT 等 AI 工具,协助配置轩辕镜像、编写 docker pull 命令、修改 Docker Compose 镜像地址、配置镜像加速、排查镜像拉取失败、分析报错日志等问题,请先让 AI 阅读并遵守轩辕镜像的规则文档。
只需在 AI 对话中先发送下面这段话即可:
请先阅读并遵守:https://xuanyuan.cloud/agents.md
未读文档前不要生成 pull 命令或排错方案。查看 agents.md 用法指南与完整示范。国内用户首推 元宝 AI、DeepSeek 的深度思考模式,不推荐豆包 AI;Cursor 等编辑器可在对话 @ 该链接,或加入 User Rules。 若 AI 无法访问外链,可 打开说明文档 复制全文粘贴。文档会随站点更新,复制内容可能过期,建议定期检查。
Pre-built, minimalist Docker images for running https://github.com/osm2pgsql-dev/osm2pgsql
The size might not be as minimal as it could be, work needs to be done to isolate runtime dependencies from build dependencies to make the final images slimmer.
There are indeed several osm2pgsql docker images floating around on dockerhub, but I found that they all had at least one deficiency:
So at the https://wiki.openstreetmap.org/wiki/Karlsruhe_Hack_Weekend_February_2024, I resolved to build a comprehensive set of minimal images that contain only osm2pgsql, built with the official instructions from the source repo.
The below example will pull the latest image and run it with no command (prints helpdocs).
Change latest to specific tag number to get that release version. Release version can be
found at the source repo's https://github.com/osm2pgsql-dev/osm2pgsql/releases.
shdocker run docker.io/iboates/osm2pgsql:latest
The image can be build locally with this command:
shelldocker build \ --tag custom-osm2pgsql-image \ --file dockerfiles/2.0.0/Dockerfile \ scripts
NOTE: osm2pgsql-replication and osm2pgsql-gen are bundled with the image for every version for which these extra
utilities are compatible. For more information about how to invoke those, see
the relevant section
The below example assumes you already have a PostGIS instance running on localhost, port 5432.
shwget -O data.pbf https://download.geofabrik.de/europe/andorra-latest.osm.pbf docker run -v $(pwd):/data -e PGPASSWORD=<your password> --network="host" iboates/osm2pgsql:latest \ -d o2p \ -U o2p \ -H 127.0.0.1 \ -P 5432 \ /data/data.pbf
Note that in order to access an existing PostGIS instance on the host machine, you must specify --network="host", so
that the container can access the port. A more sensible way of doing this is to include this image in a docker-compose
file which also contains a PostGIS instance, an example of which can be found here. If the PostGIS instance is on an
external IP, however, you should be able to omit this command.
Also note that when specifying locations of files, they must be specified using the mounted path inside the container.
In this example, we have mounted the current working directory as /data. So the PBF file we downloaded is accessible
at /data/data.pbf.
An extra feature in this image compared to a native install is that you can pass a URL to a .pbf file instead of a file path. The image will download the file, load it, then delete it afterwards:
shdocker run -v $(pwd):/data -e PGPASSWORD=<your password> --network="host" iboates/osm2pgsql:latest \ -d o2p \ -U o2p \ -H 127.0.0.1 \ -P 5432 \ https://download.geofabrik.de/europe/andorra-latest.osm.pbf
The file will be downloaded to /tmp in the container by default. You can change this if necessary by setting an
environment variable:
docker run -v $(pwd):/data -e PGPASSWORD=<your password> -e PBF_DOWNLOAD_DIR=<your download path> --network="host" iboates/osm2pgsql:latest \ -d o2p \ -U o2p \ -H 127.0.0.1 \ -P 5432 \ https://download.geofabrik.de/europe/andorra-latest.osm.pbf
The below example shows how to do an import with a custom style file
shdocker run -v $(pwd):/data -e PGPASSWORD=<your password> --network="host" iboates/osm2pgsql:latest \ -d o2p \ -U o2p \ -H 127.0.0.1 \ -P 5432 \ -O flex \ -S /data/style.lua \ https://download.geofabrik.de/europe/andorra-latest.osm.pbf
As before, note that when specifying locations of files, they must be specified using the mounted path inside the
container. In this example, we have mounted the current working directory as /data. So for this example, the PBF file
we downloaded is accessible at /data/data.pbf, and the style file must be saved in the current directory as
style.lua, and will be accessible at /data/style.lua
For more information regarding the -O flag and styles in general, please refer to the manual,
as it is a rather complex topic that is outside of the scope of the docker images.
The below example shows how to launch a more reasonable and ergonomic local deployment of osm2pgsql with an accompanying PostGIS instance:
yamlversion: '3.8' services: postgis: image: postgis/postgis:latest environment: POSTGRES_DB: o2p POSTGRES_USER: o2p POSTGRES_PASSWORD: o2p volumes: - postgis_data:/var/lib/postgresql/data ports: - "5432:5432" osm2pgsql: image: iboates/osm2pgsql:latest environment: PGPASSWORD: o2p volumes: postgis_data:
Run it like this:
shdocker compose up -d
And perform another minimal import like so:
shdocker compose run osm2pgsql \ -d o2p \ -U o2p \ -H postgis \ -P 5432 \ https://download.geofabrik.de/europe/andorra-latest.osm.pbf
The benefit here is that the PostGIS instance runs in the same network as where the osm2pgsql container will run, and we have bound its port 5432 to the host machine's port 5432, so you can connect to it directly as if it were just running locally:
shexport PGPASSWORD=o2p; psql -h 127.0.0.1 -p 5432 -d o2p -U o2p
Verify that the import was successful:
sqlSELECT osm_id FROM planet_osm_point LIMIT 1;
It's important to realize that this image actually bundles osm2pgsql (the main application) and the
accompanying utilities (osm2pgsql-replication) https://github.com/osm2pgsql-dev/osm2pgsql/blob/master/scripts/osm2pgsql-replication
(manual), osm2pgsql-expire (manual) and osm2pgsql-gen (manual). Normally, one
would execute these via these identifiers, but since the image is named osm2pgsql, it can get unwieldly to have to
use a command like docker run osm2pgsql:latest osm2pgsql-gen, so we offer a lot of flexibility on how to access them.
The below table summarizes what combination of keywords will execute which utility:
| Command | Equivalent in native install |
|---|---|
docker run osm2pgsql:latest <args> | osm2pgsql <args> |
docker run osm2pgsql:latest osm2pgsql <args> | osm2pgsql <args> |
docker run osm2pgsql:latest replication <args> | osm2pgsql-replication <args> |
docker run osm2pgsql:latest osm2pgsql-replication <args> | osm2pgsql-replication <args> |
docker run osm2pgsql:latest gen <args> | osm2pgsql-gen <args> |
docker run osm2pgsql:latest generalization <args> | osm2pgsql-gen <args> |
docker run osm2pgsql:latest osm2pgsql-generalization <args> | osm2pgsql-gen <args> |
docker run osm2pgsql:latest osm2pgsql-gen <args> | osm2pgsql-gen <args> |
docker run osm2pgsql:latest osm2pgsql-expire <args> | osm2pgsql-expire <args> |
docker run osm2pgsql:latest expire <args> | osm2pgsql-expire <args> |
osm2pgsql is primarily maintained by Jochen Topf您可以使用以下命令拉取该镜像。请将 <标签> 替换为具体的标签版本。如需查看所有可用标签版本,请访问 标签列表页面。
来自真实用户的反馈,见证轩辕镜像的优质服务
以下是 iboates/osm2pgsql 相关的常用 Docker 镜像,适用于 不同场景 等不同场景: