docker社区的geodata/gdal镜像dockerfile分析

Posted sulerzh

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了docker社区的geodata/gdal镜像dockerfile分析相关的知识,希望对你有一定的参考价值。

对应从事遥感与地理信息的同仁来说,gdal应该是所有工具中使用频度最高的库了,那么在docker中使用gdal时,面临的第一步就是构建gdal基础镜像,社区中引用最多的就是geodata提供的gdal基础镜像包,封装的gdal最新版本是2.3.0dev。

geodata/gdal的docker在github上的地址如下:

https://github.com/geo-data/gdal-docker

根据该库的提交记录,其生成gdal镜像的方法经历了多次更新:

1 最初按照gdal官网步骤自行编译;

2 基于makefile采用make系统编译;

3 基于gdal的travel ci 脚本进行编译。

dockerfile内容如下:

##
# geodata/gdal
#
# This creates an Ubuntu derived base image that installs the latest GDAL
# subversion checkout compiled with a broad range of drivers.  The build process
# is based on that defined in
# <https://github.com/OSGeo/gdal/blob/trunk/.travis.yml>
#

# Ubuntu 14.04 Trusty Tahyr
FROM ubuntu:trusty

MAINTAINER Homme Zwaagstra <hrz@geodata.soton.ac.uk>

# Install the application.
ADD . /usr/local/src/gdal-docker/
RUN /usr/local/src/gdal-docker/build.sh

# Externally accessible data is by default put in /data
WORKDIR /data
VOLUME ["/data"]

# Output version and capabilities by default.
CMD gdalinfo --version && gdalinfo --formats && ogrinfo --formats

基于ubuntu:trusty基础镜像,复制镜像构建相关内容到镜像的/usr/local/src/gdal-docker目录,利用build.sh脚本执行构建操作。

build.sh内容如下:

#!/bin/sh

##
# Install GDAL from within a docker container
#
# This script is designed to be run from within a docker container in order to
# install GDAL. It delegates to `before_install.sh` and `install.sh` which are
# patched from the Travis CI configuration in the GDAL repository.
#

set -e

DIR=$(dirname "$(readlink -f "$0")")
GDAL_VERSION=$(cat ${DIR}/gdal-checkout.txt)

export DEBIAN_FRONTEND=noninteractive

# Set the locale. Required for subversion to work on the repository.
update-locale LANG="C.UTF-8"
dpkg-reconfigure locales
. /etc/default/locale
export LANG

# Instell prerequisites.
apt-get update -y
apt-get install -y         software-properties-common         wget         unzip         subversion         ccache         clang-3.5         patch         python-dev         ant

# Everything happens under here.
cd /tmp

# Get GDAL.
svn checkout --quiet "http://svn.osgeo.org/gdal/${GDAL_VERSION}/" /tmp/gdal/

# Install GDAL.
cd /tmp/gdal

# Apply our build patches.
patch ./gdal/ci/travis/trusty_clang/before_install.sh ${DIR}/before_install.sh.patch
patch ./gdal/ci/travis/trusty_clang/install.sh ${DIR}/install.sh.patch

# Do the build.
. ./gdal/ci/travis/trusty_clang/before_install.sh
. ./gdal/ci/travis/trusty_clang/install.sh

# Clean up.
apt-get autoremove -y
apt-get clean
rm -rf /var/lib/apt/lists/partial/* /tmp/* /var/tmp/*

设置GDAL_VERSION(从gdal-checkout.txt读取,为trunk,表示从svn主干分支下载源代码),下载gdal源代码到/tmp/gdal目录,下载编译器clang和python环境,对gdal的trusty_clang的travis安装脚本打补丁(通过修改后调用diff工具生成patch),安装gdal,清理临时文件。

以上是关于docker社区的geodata/gdal镜像dockerfile分析的主要内容,如果未能解决你的问题,请参考以下文章

GitLab中文社区版Docker镜像安装启动及配置

Docker 镜像安装 GitLab 中文社区版

自制GreatSQL Docker镜像

Docker 镜像

镜像操作

Docker镜像篇