首页 > 解决方案 > 通过 Docker 或 Docker Compose 的 GDAL 图像依赖

问题描述

我正在尝试找出 Docker 和/或 Docker Compose 设置,以便在我的示例/测试应用程序中添加 GDAL 库或容器映像依赖项,以便我可以通过控制台中的 bin/bash 执行 GDAL 命令,并最终将 Web 应用程序装箱在他们自己的 Docker 容器中。

现在,我有一个我正在尝试运行的控制台应用程序,我需要依赖于现有的 Docker 映像:geodata/gdal:ubuntu-full-3.2.0。

我目前将我的 docker compose 设置如下:

version: '3.4'

services:
    gdal:
        image: "geodata/gdal:ubuntu-full-3.2.0"
    satellites.console:
        image: ${DOCKER_REGISTRY-}satellitesconsole
        build:
            context: .
            dockerfile: Satellites.Console/Dockerfile
        depends_on:
            - gdal

我的控制台应用程序的 dockerfile 只是复制、构建和发布控制台应用程序的基本框架:

#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.

FROM mcr.microsoft.com/dotnet/core/runtime:3.1-buster-slim AS base
WORKDIR /app

FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build
WORKDIR /src
COPY ["Satellites.Console/Satellites.Console.csproj", "Satellites.Console/"]
RUN dotnet restore "Satellites.Console/Satellites.Console.csproj"
COPY . .
WORKDIR "/src/Satellites.Console"
RUN dotnet build "Satellites.Console.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "Satellites.Console.csproj" -c Release -o /app/publish

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Satellites.Console.dll"]

据我了解,GDAL 容器映像应该包含并安装所有在其容器中使用 GDAL 库所需的部分。我想将这些依赖项带到我的控制台应用程序中,这样我就可以运行 bin/bash 来针对 GDAL 库运行。我希望能够通过以下方式实现这一目标:

ProcessStartInfo startInfo = new ProcessStartInfo() { FileName = "/bin/bash", Arguments = @"gdalinfo --version", RedirectStandardOutput = true, UseShellExecute = false };
Process proc = new Process() { StartInfo = startInfo, };
proc.Start();
string result = proc.StandardOutput.ReadToEnd();
System.Console.WriteLine(result);

我会以正确的方式解决这个问题吗?

我已经尝试了从当前设置到从源存储库复制 Dockerfile 以尝试在我的控制台容器中安装所有内容(我想我需要其中包含的 .sh 文件才能以这种方式安装它,但我有不知道如何处理这些,因为为其运行构建似乎不会进行任何安装或任何操作)。无论我使用什么方法,从控制台应用程序运行 bash 都没有任何运气,我得到了

/bin/bash: gdalinfo: 没有这样的文件或目录

意味着它没有安装依赖项,或者 PATHS 没有正确设置。

有没有人尝试过并成功地以这种方式设置他们的 Docker 容器环境?作为 Docker 和容器工作方式的新手,我在这一点上有点迷茫。

标签: dockerdocker-composegdal

解决方案


推荐阅读