Skip to content

Instantly share code, notes, and snippets.

@clrxbl
Last active April 28, 2024 13:22
Show Gist options
  • Save clrxbl/5697d63c669e33a8a92298f273ce3b68 to your computer and use it in GitHub Desktop.
Save clrxbl/5697d63c669e33a8a92298f273ce3b68 to your computer and use it in GitHub Desktop.
java shim
#!/bin/bash
# java shim to execute anything java within a distroless, rootless container
# designed for podman 4, breaks with podman 3 because of different --pull syntax
# https://iptables.sh
set -euo pipefail
IMAGE="gcr.io/distroless/java21:nonroot"
# check for podman
# podman runs rootless out of the box unlike docker
if ! command -v podman &> /dev/null
then
echo "podman could not be found"
exit
fi
podman run \
--rm \
-it \
--userns=keep-id:uid=65532,gid=65532 \
--network host \
--pull newer \
-v "$(pwd)":/app \
-w /app \
--entrypoint /usr/bin/java \
"$IMAGE" \
"$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment