Skip to content

Instantly share code, notes, and snippets.

@wkgcass
Last active December 4, 2023 17:18
Show Gist options
  • Save wkgcass/3db8143dde507f6678864b97f9e1c9e4 to your computer and use it in GitHub Desktop.
Save wkgcass/3db8143dde507f6678864b97f9e1c9e4 to your computer and use it in GitHub Desktop.
Dockerfile for GraalVM Native Image (can build static native-images)
FROM ubuntu:20.04
RUN apt update
RUN apt install -y wget ca-certificates build-essential zlib1g zlib1g-dev locales
# configure locales first
RUN locale-gen zh_CN
RUN locale-gen zh_CN.utf8
ENV LANG zh_CN.UTF-8
ENV LC_ALL zh_CN.UTF-8
ENV LANGUAGE zh_CN.UTF-8
RUN update-locale LANG=$LANG LC_ALL=$LC_ALL LANGUAGE=$LANGUAGE
# graal
RUN wget https://download.oracle.com/graalvm/21/latest/graalvm-jdk-21_linux-aarch64_bin.tar.gz && tar zxf graalvm-jdk-21_linux-aarch64_bin.tar.gz && rm graalvm-jdk-21_linux-aarch64_bin.tar.gz && mv graalvm-jdk-21.0.1+12.1 graalvm-jdk-21
ENV JAVA_HOME /graalvm-jdk-21
ENV PATH="$PATH:/$JAVA_HOME/bin"
RUN mkdir -p /workdir
WORKDIR /workdir
FROM ubuntu:20.04
RUN apt update
RUN apt install -y wget ca-certificates build-essential zlib1g zlib1g-dev locales
# configure locales first
RUN locale-gen zh_CN
RUN locale-gen zh_CN.utf8
ENV LANG zh_CN.UTF-8
ENV LC_ALL zh_CN.UTF-8
ENV LANGUAGE zh_CN.UTF-8
RUN update-locale LANG=$LANG LC_ALL=$LC_ALL LANGUAGE=$LANGUAGE
# graal
RUN wget https://download.oracle.com/graalvm/21/latest/graalvm-jdk-21_linux-x64_bin.tar.gz && tar zxf graalvm-jdk-21_linux-x64_bin.tar.gz && rm graalvm-jdk-21_linux-x64_bin.tar.gz && mv graalvm-jdk-21.0.1+12.1 graalvm-jdk-21
ENV JAVA_HOME /graalvm-jdk-21
ENV PATH="$PATH:/$JAVA_HOME/bin"
# to build static native-image:
RUN mkdir -p /toolchain
WORKDIR /toolchain
RUN wget http://more.musl.cc/10/x86_64-linux-musl/x86_64-linux-musl-native.tgz && tar zxf x86_64-linux-musl-native.tgz && rm x86_64-linux-musl-native.tgz
ENV TOOLCHAIN_DIR /toolchain/x86_64-linux-musl-native
ENV CC="$TOOLCHAIN_DIR/bin/gcc"
ENV PATH="$PATH:$TOOLCHAIN_DIR/bin"
RUN wget https://zlib.net/zlib-1.3.tar.gz && tar zxf zlib-1.3.tar.gz && rm zlib-1.3.tar.gz
WORKDIR /toolchain/zlib-1.3
RUN ./configure --prefix=$TOOLCHAIN_DIR --static
RUN make && make install
WORKDIR /
RUN mkdir -p /workdir
WORKDIR /workdir
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment