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-alpine

RUN 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.