feat: init
This commit is contained in:
commit
667709b526
5 changed files with 107 additions and 0 deletions
54
Dockerfile_base
Normal file
54
Dockerfile_base
Normal file
|
@ -0,0 +1,54 @@
|
|||
# Stage 1: Build the base system
|
||||
FROM busybox:1.37.0 AS builder
|
||||
|
||||
# Set working directory
|
||||
WORKDIR /build
|
||||
|
||||
# Define build arguments
|
||||
ARG BASE_FILES_VERSION=13.7
|
||||
ARG LIBGCC_VERSION=14.2.0-19
|
||||
ARG GLIBC_VERSION=2.41-6
|
||||
ARG TZDATA_VERSION=2025b-1
|
||||
|
||||
# Download required Debian packages
|
||||
RUN wget -q \
|
||||
https://ftp.debian.org/debian/pool/main/b/base-files/base-files_${BASE_FILES_VERSION}_amd64.deb \
|
||||
https://ftp.debian.org/debian/pool/main/g/gcc-14/libgcc-s1_${LIBGCC_VERSION}_amd64.deb \
|
||||
https://ftp.debian.org/debian/pool/main/g/glibc/libc6_${GLIBC_VERSION}_amd64.deb \
|
||||
https://ftp.debian.org/debian/pool/main/g/glibc/libc-bin_${GLIBC_VERSION}_amd64.deb \
|
||||
https://ftp.debian.org/debian/pool/main/t/tzdata/tzdata_${TZDATA_VERSION}_all.deb
|
||||
|
||||
# Extract and clean up the downloaded packages
|
||||
RUN mkdir -p var/lib/dpkg && \
|
||||
for deb in *.deb; do \
|
||||
echo "Processing $deb" && \
|
||||
ar x $deb control.tar.xz data.tar.xz && \
|
||||
tar xf data.tar.xz && tar xf control.tar.xz ./control && \
|
||||
(cat control; echo) >> var/lib/dpkg/status && \
|
||||
rm -f $deb control.tar.xz data.tar.xz control; \
|
||||
done && \
|
||||
# Create a non-root user directory
|
||||
mkdir -p /home/nonroot && \
|
||||
chown 65532:65532 /home/nonroot && \
|
||||
# Copy nsswitch.conf for proper name resolution
|
||||
cp usr/share/libc-bin/nsswitch.conf etc/nsswitch.conf && \
|
||||
# Remove unnecessary files to reduce image size
|
||||
rm -rf usr/bin usr/sbin usr/share/base-files usr/share/common-licenses usr/share/doc \
|
||||
usr/share/libc-bin usr/share/lintian usr/share/man usr/lib/x86_64-linux-gnu/gconv && \
|
||||
find usr/share/zoneinfo ! -name "Paris" ! -name "UTC" ! -name "New_York" -delete
|
||||
|
||||
# Stage 2: Temporary scratch image
|
||||
FROM scratch AS tmp
|
||||
|
||||
# Copy root directory and extracted files from the builder stage
|
||||
COPY rootdir/ /
|
||||
COPY --from=builder /build/ /
|
||||
|
||||
# Stage 3: Final minimal image
|
||||
FROM scratch
|
||||
|
||||
# Set environment variables
|
||||
ENV LANG=C.utf8
|
||||
|
||||
# Copy everything from the temporary stage
|
||||
COPY --from=tmp / /
|
36
Dockerfile_java
Normal file
36
Dockerfile_java
Normal file
|
@ -0,0 +1,36 @@
|
|||
# Define build arguments
|
||||
ARG JAVA_VERSION=21.0.6+7
|
||||
|
||||
FROM busybox:1.37.0 AS builder
|
||||
|
||||
# Set working directory
|
||||
WORKDIR /build
|
||||
|
||||
# Define build arguments
|
||||
ARG JAVA_VERSION
|
||||
ARG JAVA_HOME=opt/java/openjdk
|
||||
|
||||
# Download and extract OpenJDK
|
||||
RUN MAJOR=$(echo ${JAVA_VERSION} | cut -d'.' -f1) && \
|
||||
VERSION_UNDERSCORE=$(echo ${JAVA_VERSION} | sed 's/+/_/') && \
|
||||
wget -q https://github.com/adoptium/temurin${MAJOR}-binaries/releases/download/jdk-${JAVA_VERSION}/OpenJDK${MAJOR}U-jre_x64_linux_hotspot_${VERSION_UNDERSCORE}.tar.gz && \
|
||||
mkdir -p $JAVA_HOME && \
|
||||
tar xf OpenJDK${MAJOR}U-jre_x64_linux_hotspot_${VERSION_UNDERSCORE}.tar.gz -C $JAVA_HOME --strip-components 1 --no-same-owner && \
|
||||
rm -rf $JAVA_HOME/legal OpenJDK${MAJOR}U-jre_x64_linux_hotspot_${VERSION_UNDERSCORE}.tar.gz
|
||||
|
||||
# Use a minimal base image
|
||||
FROM base
|
||||
|
||||
# Define build arguments
|
||||
ARG JAVA_VERSION
|
||||
|
||||
# Set environment variables
|
||||
ENV JAVA_HOME=/opt/java/openjdk
|
||||
ENV JAVA_VERSION=$JAVA_VERSION
|
||||
ENV PATH=$JAVA_HOME/bin:$PATH
|
||||
|
||||
# Copy Java runtime from the builder stage
|
||||
COPY --from=builder /build /
|
||||
|
||||
# Set the default command
|
||||
ENTRYPOINT ["java"]
|
11
build.sh
Executable file
11
build.sh
Executable file
|
@ -0,0 +1,11 @@
|
|||
#!/bin/sh
|
||||
set -e
|
||||
|
||||
docker build -t base -f Dockerfile_base .
|
||||
docker run --rm -it --entrypoint /lib64/ld-linux-x86-64.so.2 base --version
|
||||
|
||||
#docker build --build-arg JAVA_VERSION=17.0.14+7 -t java17 -f Dockerfile.java .
|
||||
#docker run --rm -it java17 java --version
|
||||
|
||||
docker build -t java21 -f Dockerfile_java .
|
||||
docker run --rm -it java21 --version
|
3
rootdir/etc/group
Normal file
3
rootdir/etc/group
Normal file
|
@ -0,0 +1,3 @@
|
|||
root:x:0:
|
||||
nobody:x:65534:
|
||||
nonroot:x:65532:
|
3
rootdir/etc/passwd
Normal file
3
rootdir/etc/passwd
Normal file
|
@ -0,0 +1,3 @@
|
|||
root:x:0:0:root:/root:/sbin/nologin
|
||||
nobody:x:65534:65534:nobody:/nonexistent:/sbin/nologin
|
||||
nonroot:x:65532:65532:nonroot:/home/nonroot:/sbin/nologin
|
Loading…
Add table
Add a link
Reference in a new issue