Skip to content

Instantly share code, notes, and snippets.

@harishkannarao
Last active March 26, 2024 14:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save harishkannarao/787b4a10659dc8d0cf6cc5b6e8902e93 to your computer and use it in GitHub Desktop.
Save harishkannarao/787b4a10659dc8d0cf6cc5b6e8902e93 to your computer and use it in GitHub Desktop.
Build an alpine image with jq, curl and jre 11 from scratch without pulling from hub.docker.com
#!/bin/sh
# Make the script to abort if any command fails. Use set +e to change the behaviour and ignore failed command.
set -e
# Prints the commands as it is executed. Useful for debugging. Use set +x to disable debugging.
set -x
# Set default values
ORGANISATION_NAME="${ORGANISATION_NAME:-com.example}"
BASE_IMAGE_NAME="${BASE_IMAGE_NAME:-alpine-jre-11}"
BASE_IMAGE_TAG="${BASE_IMAGE_TAG:-latest}"
# Delete/Cleanup the downloaded directory
rm -rf temp_alpine_docker
mkdir temp_alpine_docker
# Get the latest version name of alpine linux
latest_file_name=$(curl -s "https://dl-cdn.alpinelinux.org/alpine/latest-stable/releases/x86_64/latest-releases.yaml" | grep 'file:' | grep -o 'alpine-minirootfs.*gz')
# Print the latest version name
echo $latest_file_name
# Download the latest version of alpine linux
curl -s "https://dl-cdn.alpinelinux.org/alpine/latest-stable/releases/x86_64/$latest_file_name" --output temp_alpine_docker/alpine-minirootfs-latest.tar.gz
cat <<DOCKERFILE > temp_alpine_docker/Dockerfile
FROM scratch
ADD alpine-minirootfs-latest.tar.gz /
RUN apk --update add jq
RUN apk --update add curl
RUN apk --update add openjdk11-jre
CMD ["/bin/sh"]
DOCKERFILE
# Build a docker image with the latest version
docker build --pull -t $ORGANISATION_NAME/$BASE_IMAGE_NAME:$BASE_IMAGE_TAG -f temp_alpine_docker/Dockerfile temp_alpine_docker
# Delete/Cleanup the downloaded directory
rm -rf temp_alpine_docker
# Run the image as
# docker run --rm -it com.example/alpine-jre-11:latest
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment