Note: Cram has been moved into Jib as the Jib CLI utility
Cram is a little Java-based command-line utility for building Docker containers from file system content. It serves as a demonstration of Jib Core, a Java library for building containers without Docker.
(Cram was initially called Bilge, because a Jib is also a sail and... hence the rename.)
mvn package
This creates a fatjar in target/cram-0.0.1-SNAPSHOT-jar-with-dependencies.jar
.
The following example creates an nginx-based container to serve static content that is found in path/to/website
.
The result is loaded to the local Docker daemon as my-static-website
:
$ java -jar cram/target/cram-0.0.1-SNAPSHOT-jar-with-dependencies.jar \
--docker \
nginx \
my-static-website \
--port 80 \
--entrypoint "nginx,-g,daemon off;" \
path/to/website:/usr/share/nginx/html
$ docker run -it --rm -p 8080:80 my-static-website
The following example uses cram to containerize itself. The image is pushed to a registry at localhost:5000
:
$ java -jar cram/target/cram-0.0.1-SNAPSHOT-jar-with-dependencies.jar \
--registry \
gcr.io/distroless/java \
localhost:5000/cram:latest \
--insecure \
--entrypoint "java,-jar,/app/cram.jar" \
cram/target/cram-0.0.1-SNAPSHOT-jar-with-dependencies.jar:/app/cram.jar
$ docker run --rm localhost:5000/cram:latest
We need to use --insecure
assuming the local registry does not support SSL.
Note that we'd be better off using jib-maven-plugin
to create the container since it would create better layer strategy that negates the need to use a fatjar.
$ sh build-native.sh
- switched to using SLF4j with Apache Commons Logging facade to avoid
the need to configure reflection for
LogFactory
- must explicitly enable
http
andhttps
support - must somehow set
java.library.path
at compile time, or copy in $GRAALVM/jre/lib/libsunec.* into the current directory, to make the SunEC JCA extensions available. - the
graal-jib-reflect.json
must be updated as Jib Core adds new fields to Jackson JSON templates.