Skip to content

Instantly share code, notes, and snippets.

@Duvel
Last active July 21, 2019 13:49
Show Gist options
  • Save Duvel/f10d8c15fcd45161293418b63739bd0d to your computer and use it in GitHub Desktop.
Save Duvel/f10d8c15fcd45161293418b63739bd0d to your computer and use it in GitHub Desktop.
Build a postgis and osm2pgsql Docker image on a Raspberry Pi

Build a postgis and osm2pgsql Docker image on a Raspberry Pi

Currently it is a challenge to build a small Docker image for postgis and psm2pgsql. This is due to a package in Alpine testing.

With the help of a few GitHub projects I managed to create the images. I will document my steps here.

First setup your build environment

Instead of raspbian I use hypriot as my OS for hosting Docker containers.

SSH into your Raspberry Pi and create a source folder if you don't already have one.

mkdir src
cd src

First build the alpine package

I found a good project that helps in building Alpine packages: dnephin/docker-apk-build. I adapted this project to be able to compile for Alpine 3.10.

git clone https://github.com/Duvel/docker-apk-build

cd docker-apk-build

You can start the build environment with:

make build

and a build image will be created and started.

First you need to do some setup:

~/bin/setup.sh

The problematic package is proj4 and the newest version 6 also gives issues when compiling with osm2pgsql, so we will checkout version 5.2.0. After that we will create and sign the image.

git checkout 9f72f605cf4187e49a9b311c82084faa2174e5cc

cd /work/testing/proj4/
abuild -c -r -P /target

cd /target/testing/armv7/
apk index -o APKINDEX.tar.gz *.apk
abuild-sign APKINDEX.tar.gz

exit

Leave the build folder:

cd ~/src

Build the postgis image

I created a clone of the docker postgis image appropriate/docker-postgis and adjusted it to use the locally build package.

git clone https://github.com/Duvel/docker-postgis

cd docker-postgis/10-2.5/alpine

Copy the build package and keys to the build-dir:

cp -r ~/src/docker-apk-build/target .
cp -r ~/src/docker-apk-build/user.abuild .

Now you can build the image:

docker build -t duvel/postgis:10-alpine-armv6 .

Leave the build folder:

cd ~/src

Build the osm2pgsql image

Now we also can build the osm2pgsql image, which I cloned from stefda/osm2pgsql.

git clone https://github.com/Duvel/osm2pgsql

cd osm2pgsql

Copy the build package and keys to the build-dir:

cp -r ~/src/docker-apk-build/target .
cp -r ~/src/docker-apk-build/user.abuild .

Now you can build the image:

docker build -t duvel/osm2pgsql:0.96-armv6 .

Leave the build folder:

cd ~/src

Final images

I pushed the final images to the docker hub, so you can easily pull them:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment