英文:
Problem with using self-built GDAL in Docker
问题
I am trying to prepare an Ubuntu 22.04 Docker image with GDAL 3.2.2. This GDAL installation needs to have ECW support, which means I cannot use the pre-built gdal-bin package that can be installed using apt.
我正在尝试准备一个带有GDAL 3.2.2的Ubuntu 22.04 Docker镜像。这个GDAL安装需要支持ECW,这意味着我不能使用可以使用apt安装的预构建的gdal-bin软件包。
I can build and install GDAL with these specs in the Docker container. But when running a simple test command on a simple tiff file I get an error that I have no idea how to debug.
我可以在Docker容器中使用这些规格构建和安装GDAL。但是,当在一个简单的tiff文件上运行一个简单的测试命令时,我会收到一个错误,我不知道如何调试。
$ gdalinfo --version
GDAL 3.2.2, released 2021/03/05
$ gdalinfo test.tif
Driver: GTiff/GeoTIFF
Files: test.tif
Size is 572, 577
Aborted (core dumped)
The steps I took was starting with a regular Ubuntu 22.04 Docker image. Installing prerequisites (gcc and stuff). Downloading the ECW SDK. Install that. Download the source of gdal 3.2.2. Configure the build to include ECW. Use the make file to build and then install.
我采取的步骤是从常规的Ubuntu 22.04 Docker镜像开始。安装先决条件(如gcc等)。下载ECW SDK。安装它。下载gdal 3.2.2的源代码。配置构建以包括ECW。使用make文件进行构建,然后安装。
If I do not use a self-built GDAL but rather install gdal-bin using apt directly, it works for the tiff file, but it would mean I have no ECW support.
如果我不使用自己构建的GDAL,而是直接使用apt安装gdal-bin,它可以用于tiff文件,但这意味着我没有ECW支持。
I have also successfully built and used GDAL with ECW directly on Ubuntu 22.04 without Docker.
我也曾在Ubuntu 22.04上成功地直接构建和使用带有ECW支持的GDAL,而没有使用Docker。
Does anyone know a solution for this or have any idea in which direction I could look to potentially debug it?
有没有人知道这个问题的解决方案,或者有没有任何可能用于调试的方向?
英文:
I am trying to prepare an Ubuntu 22.04 Docker image with GDAL 3.2.2. This GDAL installation needs to have ECW support, which means I cannot use the pre-built gdal-bin package that can be installed using apt.
I can build and install GDAL with these specs in the Docker container. But when running a simple test command on a simple tiff file I get an error that I have no idea how to debug.
$ gdalinfo --version
GDAL 3.2.2, released 2021/03/05
$ gdalinfo test.tif
Driver: GTiff/GeoTIFF
Files: test.tif
Size is 572, 577
Aborted (core dumped)
The steps I took was starting with a regular Ubuntu 22.04 Docker image. Installing prerequisites (gcc and stuff). Downloading the ECW SDK. Install that. Download the source of gdal 3.2.2. Configure the build to include ECW. Use the make file to build and then install.
If I do not use a self-built GDAL but rather install gdal-bin using apt directly, it works for the tiff file, but it would mean I have no ECW support.
I have also successfully built and used GDAL with ECW directly on Ubuntu 22.04 without Docker.
Does anyone know a solution for this or have any idea in which direction I could look to potentially debug it?
答案1
得分: 1
你可以尝试使用专用的Docker镜像,比如klokantech/gdal
来执行相同的过程。
docker run -ti --rm -v $(pwd):/data klokantech/gdal gdalinfo yourfile.tif
这个容器非常小(约350MB),并且使用了最新稳定版本的GDAL,包括MrSID、ECW和JP2KAK驱动程序。
由于Dockerfile相当旧,你可以从中重新构建自己的镜像,确保获得正确版本的GDAL。
这个Dockerfile安装了支持ECW的GDAL,这正是你所需要的。
但是,它有一些潜在的问题:
-
Dockerfile使用了Debian 7作为基础镜像,这相当古老。你提到你使用Ubuntu 22.04作为基础镜像,它要新得多。
-
Dockerfile安装的是GDAL版本1.11.1,但你想安装GDAL 3.2.2。
-
Dockerfile需要使用私有URL下载ECW和其他SDK。你需要将这些替换为实际可以下载这些SDK的URL。
要使用这个Dockerfile,你需要进行一些更改:
-
将基础镜像从Debian 7更改为Ubuntu 22.04(或者如果你更喜欢的话,可能是更新的Debian版本)。
-
将GDAL版本从1.11.1更改为3.2.2。
-
将
SDKS_URL
环境变量中的占位符替换为实际可以下载ECW和其他SDK的URL。
一旦你做出了这些更改,你应该能够构建一个满足你要求的Docker镜像。
类似于:
FROM ubuntu:22.04
ENV DEBIAN_FRONTEND noninteractive
RUN apt-get -qq update && apt-get -qq -y --no-install-recommends install \
autoconf \
automake \
build-essential \
curl \
libcurl4-gnutls-dev \
libepsilon-dev \
libexpat1-dev \
libfreexl-dev \
libgeos-dev \
libgif-dev \
libhdf4-alt-dev \
libhdf5-serial-dev \
libjpeg-dev \
liblcms2-dev \
liblzma-dev \
libnetcdf-dev \
libpcre3-dev \
libpng-dev \
libpodofo-dev \
libpoppler-dev \
libproj-dev \
libspatialite-dev \
libsqlite3-dev \
libtbb2 \
libwebp-dev \
libxerces-c-dev \
libxml2-dev \
netcdf-bin \
poppler-utils \
python3-dev \
unixodbc-dev \
unzip
ENV SDKS_URL http://your.url.here
ENV ECW_VERSION 3.3
ENV ECW_DATE 2006-09-06
ENV ECW_NAME libecwj2-$ECW_VERSION
ENV ECW_DIR /usr/local/src/$ECW_NAME
RUN curl -s $SDKS_URL/$ECW_NAME-$ECW_DATE.zip -o $ECW_DIR.zip \
&& unzip -q $ECW_DIR.zip -d /usr/local/src \
&& cd $ECW_DIR \
&& ./configure --prefix=/usr/local \
&& make \
&& make install
# Remove MRSID and KAKADU if not needed
# ...
ENV GDAL_VERSION 3.2.2
RUN mkdir -p /usr/local/src \
&& curl -s http://download.osgeo.org/gdal/$GDAL_VERSION/gdal-$GDAL_VERSION.tar.gz \
| tar xz -C /usr/local/src
WORKDIR /usr/local/src/gdal-$GDAL_VERSION
RUN ./configure \
--prefix=/usr/local \
--without-libtool \
--with-ecw=/usr/local \
--with-epsilon \
--with-libkml \
--with-liblzma \
--with-podofo \
--with-poppler \
--with-python \
--with-spatialite \
--with-threads \
--with-webp \
&& make \
&& make install \
&& ldconfig
你需要将http://your.url.here
替换为你托管ECW SDK的实际URL,并根据需要调整版本(参见GDAL wiki ECW)。
此外,请注意,我已经删除了MRSID和KAKADU的安装步骤,因为我假设你不需要它们。如果需要的话,你需要将它们恢复,并根据需要调整URL和版本。
Dirk Eddelbuettel在评论中补充说:
或者,如果你熟悉如何构建
.deb
包,你可以修改现有的二进制包gdal-bin
(以及libgdal-dev
等),我以前曾经这样做过,以添加TileDB支持。由Canonical提供的Launchpad站点可以为各种发布版本构建和托管二进制包;我经常用这个来制作更新的Debian软件包的“本地”版本(在周末刚刚为mlpack
做了这个)。
然后,.deb
文件可以相当轻松地放入你的(快得多!)Docker构建步骤中。
在这里,与其直接从源代码构建GDAL,这种方法涉及修改现有的Debian软件包(gdal-bin
,libgdal-dev
等)以包括ECW支持,然后从这些修改过的源代码构建.deb
软件包。然后,你可以在Docker容器中安装这些.deb
软件包。
这种方法有一些优点:
-
更快的Docker构建:直接从源代码构建GDAL可能需要很长时间。如果你有预构建的
.deb
软件包,你可以在Dockerfile中使用apt
安装它们,这会快得多。 -
更容易维护:一
英文:
You can try the same process using a dedicated Docker iage like klokantech/gdal
docker run -ti --rm -v $(pwd):/data klokantech/gdal gdalinfo yourfile.tif
> The container is minimal (about 350 MB) and is compiled from latest stable GDAL with MrSID, ECW and JP2KAK drivers.
Since the Dockerfile is quite old, you can rebuild your own image from it, making sure you get the right version of GDAL.
This Dockerfile does install GDAL with ECW support, which is what you need.
However, it has a few potential issues:
-
The Dockerfile uses Debian 7 as the base image, which is quite old. You mentioned you are using Ubuntu 22.04 as your base image, which is much newer.
-
The Dockerfile installs GDAL version 1.11.1, but you want to install GDAL 3.2.2.
-
The Dockerfile requires private URLs to download the ECW and other SDKs. You will need to replace these with the actual URLs where these SDKs can be downloaded.
To use this Dockerfile, you would need to make a few changes:
-
Change the base image from Debian 7 to Ubuntu 22.04 (or possibly an updated version of Debian if you prefer that).
-
Change the GDAL version from 1.11.1 to 3.2.2.
-
Replace the placeholders in the
SDKS_URL
environment variable with the actual URLs where the ECW and other SDKs can be downloaded.
Once you have made these changes, you should be able to build a Docker image that meets your requirements.
Something like:
FROM ubuntu:22.04
ENV DEBIAN_FRONTEND noninteractive
RUN apt-get -qq update && apt-get -qq -y --no-install-recommends install \
autoconf \
automake \
build-essential \
curl \
libcurl4-gnutls-dev \
libepsilon-dev \
libexpat1-dev \
libfreexl-dev \
libgeos-dev \
libgif-dev \
libhdf4-alt-dev \
libhdf5-serial-dev \
libjpeg-dev \
liblcms2-dev \
liblzma-dev \
libnetcdf-dev \
libpcre3-dev \
libpng-dev \
libpodofo-dev \
libpoppler-dev \
libproj-dev \
libspatialite-dev \
libsqlite3-dev \
libtbb2 \
libwebp-dev \
libxerces-c-dev \
libxml2-dev \
netcdf-bin \
poppler-utils \
python3-dev \
unixodbc-dev \
unzip
ENV SDKS_URL http://your.url.here
ENV ECW_VERSION 3.3
ENV ECW_DATE 2006-09-06
ENV ECW_NAME libecwj2-$ECW_VERSION
ENV ECW_DIR /usr/local/src/$ECW_NAME
RUN curl -s $SDKS_URL/$ECW_NAME-$ECW_DATE.zip -o $ECW_DIR.zip \
&& unzip -q $ECW_DIR.zip -d /usr/local/src \
&& cd $ECW_DIR \
&& ./configure --prefix=/usr/local \
&& make \
&& make install
# Remove MRSID and KAKADU if not needed
# ...
ENV GDAL_VERSION 3.2.2
RUN mkdir -p /usr/local/src \
&& curl -s http://download.osgeo.org/gdal/$GDAL_VERSION/gdal-$GDAL_VERSION.tar.gz \
| tar xz -C /usr/local/src
WORKDIR /usr/local/src/gdal-$GDAL_VERSION
RUN ./configure \
--prefix=/usr/local \
--without-libtool \
--with-ecw=/usr/local \
--with-epsilon \
--with-libkml \
--with-liblzma \
--with-podofo \
--with-poppler \
--with-python \
--with-spatialite \
--with-threads \
--with-webp \
&& make \
&& make install \
&& ldconfig
You will need to replace http://your.url.here
with the actual URL where you are hosting the ECW SDK. And adjust its version (see GDAL wiki ECW)
Also, note that I have removed the installation steps for MRSID and KAKADU as I assumed you do not need those. If you do, you will need to put them back in and adjust the URLs and versions as necessary.
Dirk Eddelbuettel adds in the comments:
> Alternatively, if you are familiar with building a .deb
you can modify the existing binary package gdal-bin
(and libgdal-dev
etc) which I had done in the past to add TiileDB support. The Launchpad site by Canonical can build and host the binaries for various releases; I use this regularly for "local" version of updated Debian packages (and just did so on the weekend for mlpack
).
The .deb
files then go rather easily into your (much quicker !!) Docker build step.
Here, instead of building GDAL directly from source, this approach involves modifying the existing Debian packages (gdal-bin
, libgdal-dev
, etc.) to include ECW support, and then building .deb
packages from those modified sources. You can then install these .deb
packages in your Docker container.
This approach has a couple of advantages:
-
Faster Docker builds: Building GDAL from source can take a long time. If you have pre-built
.deb
packages, you can install them withapt
in your Dockerfile, which is much faster. -
Easier maintenance: Once you have the
.deb
packages, you can use them in multiple Dockerfiles without having to repeat the complex GDAL build process.
The basic steps to follow are:
-
Modify the GDAL source code to include ECW support. This is similar to what you were doing before, but instead of building GDAL directly, you will build a
.deb
package. -
Build the
.deb
packages. This can be done using a tool likedpkg-buildpackage
. -
Upload the
.deb
packages to a repository. You can use a personal package archive (PPA) on Launchpad for this. -
In your Dockerfile, add the PPA to your list of repositories and install the GDAL packages with
apt
.
Your Dockerfile would include something like:
FROM ubuntu:22.04
ENV DEBIAN_FRONTEND noninteractive
RUN apt-get -qq update && apt-get -qq -y --no-install-recommends install \
software-properties-common \
apt-transport-https \
curl
# Add your PPA to the list of repositories
RUN add-apt-repository ppa:your/launchpad/ppa
# Update the package list and install the modified GDAL packages
RUN apt-get update && apt-get install -y \
gdal-bin \
libgdal-dev \
# other GDAL packages as needed
Replace ppa:your/launchpad/ppa
with the actual PPA where you are hosting the .deb
packages.
Keep in mind that this is a high-level overview. Modifying Debian packages, building .deb
packages, and using Launchpad are all complex tasks that require a good understanding of the Debian packaging system. If you're not already familiar with these processes, you may want to stick with the first approach.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论