我有一个 API 需要 gbak 才能工作,因为此调用:
String command = "gbak -b -v -g -user " + username + " -password " + password + " " + databasePath + " " + backupPathUpdated;
ProcessBuilder processBuilder = new ProcessBuilder(command.split(" "));
processBuilder.redirectErrorStream(true);
Process process = processBuilder.start();
process.waitFor();
我创建了一个像这样的dockerfile:
# Use an official OpenJDK runtime as a parent image
FROM openjdk:17-alpine
# Set the working directory to /app
WORKDIR /app
# Copy the current directory contents into the container at /app
COPY . /app
# Make port 8080 available to the world outside this container
EXPOSE 8080
# Run application when the container launches
CMD ["java", "-jar", "target/poc-docker-0.0.1-SNAPSHOT.jar"]
但是当我尝试运行图像时,我遇到了这个错误:
Java.io.IOException: Cannot run program "gbak": error=2, No such file or directory
at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1142)
at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1073)
at xxxxxxxxxxxxxxxxxxxxxxxxxxxx.BackupSchedulerService.getBackup(BackupSchedulerService.java:52)
at xxxxxxxxxxxxxxxxxxxxxxxxxxxx.BackupSchedulerService.lambda$executeBackup$0(BackupSchedulerService.java:35)
at java.base/java.lang.Thread.run(Thread.java:831)
Caused by: java.io.IOException: error=2, No such file or directory
at java.base/java.lang.ProcessImpl.forkAndExec(Native Method)
at java.base/java.lang.ProcessImpl.<init>(ProcessImpl.java:313)
at java.base/java.lang.ProcessImpl.start(ProcessImpl.java:244)
at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1109)
... 4 more
我尝试将我的 dockerfile 更改为:
# Use an official OpenJDK runtime as a parent image
FROM openjdk:17-alpine
# Set the working directory to /app
WORKDIR /app
# Install gbak
RUN apk --no-cache add firebird
# Copy the current directory contents into the container at /app
COPY . /app
# Make port 8080 available to the world outside this container
EXPOSE 8080
# Run application when the container launches
CMD ["java", "-jar", "target/poc-docker-0.0.1-SNAPSHOT.jar"]
但是我无法创建图像,这是错误:
=> ERROR [3/4] RUN apk --no-cache add firebird 1.3s
8 | >>> RUN apk --no-cache add firebird
9 |
10 | # Copy the current directory contents into the container at /app
--------------------
我该如何解决我的问题?
我尝试更改 dockerfile,以具有 gbak 依赖项,但出现另一个错误。
Alpine 软件包存储库中似乎没有 firebird 软件包? 我建议尝试在 dockerfile 中手动下载并安装 firebird 数据库服务器工具,类似于此:
# firebird download and install
RUN wget https://github.com/FirebirdSQL/firebird/releases/download/R3_0_9/Firebird-3.0.9.53074-0.amd64.tar.gz \
&& tar -xzf Firebird-3.0.9.53074-0.amd64.tar.gz \
&& cd Firebird-3.0.9.53074-0.amd64 \
&& ./install.sh -silent
考虑到我伪造了 github 链接,您需要根据您的要求更改它。让我知道手动安装是否可以解决您的问题