How to make curl available in Docker image based java:8-jdk-alpine and keep the image clean? How to make curl available in Docker image based java:8-jdk-alpine and keep the image clean? docker docker

How to make curl available in Docker image based java:8-jdk-alpine and keep the image clean?


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-alpineRUN apk add --update \    curl \    && rm -rf /var/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

This avoids the need to use --update and remove /var/cache/apk/* when done installing packages.

Reference -https://github.com/gliderlabs/docker-alpine/blob/master/docs/usage.md and Thank you @Daniel for the comment.


Your example dockerfile contains multiple FROM statements. This is valid but as the documentation says each FROM clears the state from previous instructions. And so the fresh installed curl is wiped after the second FROM.


Most languages have readily available HTTP clients these days; you should almost never be calling out to curl from a program in a language more sophisticated than a shell script. java.net.URLConnection has been a part of Java since Java 1.0 and (without knowing why you're trying to shell out for this) it's almost definitely the right tool here.

Assuming you control the executeCoreAPI method from your backtrace, you should change it to use the built-in Java HTTP client, and just delete all of the Dockerfile parts that try to install curl.