问题描述
我们有运行curl命令的Java代码以获取某些结果。
We are having java code that runs curl command to fetch the some result.
我们已经构建了一个jar文件,并且jar文件执行得很好
We have built a jar file and the jar file executes fine
现在,当我们尝试对Java程序进行dokerize(使用jar)并在docker中运行该应用程序时,会出现以下错误:
Now, when we try to dokerize the java program (using jar) and run the application in docker we get this error:
errorjava.io.IOException: Cannot run program "curl": error=2, No such file or directory
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1048)
at com.ps.api.common.CoreAPI_Spec.executeCoreAPI(CoreAPI_Spec.java:295)
at com.ps.api.common.CoreAPI_Spec.getAccessTokens(CoreAPI_Spec.java:319)
使用的Dockerfile:
Dockerfile used :
FROM ubuntu:16.04
MAINTAINER niro;
# Install prerequisites
RUN apt-get update && apt-get install -y \
curl
FROM java:8-jdk-alpine
# Set the working directory to /app
WORKDIR /Users/******/Desktop/CoreAPI_Jar
# Copy the current directory contents into the container at /app
ADD *******_Automation-0.0.1-SNAPSHOT-jar-with-dependencies.jar ******_Automation-0.0.1-SNAPSHOT-jar-with-dependencies.jar
# Run app.py when the container launches
CMD ["java", "-jar", "******-0.0.1-SNAPSHOT-jar-with-dependencies.jar"]
推荐答案
您使用的Java基本映像是Alpine Linux one,并且还需要从那里下载curl软件包。这是我用于生产部署的Dockerfile。
The Java base image you are using is Alpine Linux one and curl package also needs to be downloaded from there. Here is Dockerfile I have used for Production deployments.
FROM openjdk:8-jre-alpine
RUN apk add --update \
curl \
&& rm -rf /var/cache/apk/*
更新05 / 2019
从Alpine Linux 3.3开始,对于-no-cache 选项> apk 。它允许用户使用实时更新和使用的索引来安装软件包,而不是在本地缓存:
Update 05/2019
As of Alpine Linux 3.3 there exists a new --no-cache
option for apk
. It allows users to install packages with an index that is updated and used on-the-fly and not cached locally:
FROM openjdk:8-jre-alpine
RUN apk --no-cache add curl
这避免了使用-更新
并在完成安装软件包后删除 / var / cache / apk / *
。
This avoids the need to use --update
and remove /var/cache/apk/*
when done installing packages.
参考-
,谢谢@Daniel的评论。
Reference -https://github.com/gliderlabs/docker-alpine/blob/master/docs/usage.md and Thank you @Daniel for the comment.
这篇关于如何使curl在基于Java:8-jdk-alpine的Docker映像中可用并保持映像清洁?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!