Last active
September 11, 2024 12:10
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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