You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
docker run --rm native-builder -Djava.io.tmpdir=/home/user/tmp
chạy bash trong dockerd, để xem
docker run --rm -it --entrypoint sh native-builder
đổi port ngoài 8880, port nội bộ của docker là 8080
docker run --rm -p 8880:8080 native-builder
Dockerfile-native-image
FROM ghcr.io/graalvm/native-image-community:latest
# Cài thư viện để build staticRUN microdnf install -y \
gcc \
gcc-c++ \
zlib-devel \
maven \
bash \
&& microdnf clean all
WORKDIR /app
COPY . .
RUN mvn clean package -Pnative
Dockerfile-native-image-mini
# ----------------------------------------------------------------------# STAGE 1: BUILDER - Biên dịch ứng dụng thành Native Executable# SỬ DỤNG JAVA 25: Đã cập nhật tag GraalVM Community Edition lên `:25`FROM ghcr.io/graalvm/native-image-community:latest AS builder
# Đặt thư mục làm việc và sao chép mã nguồnWORKDIR /app
COPY . .
# Cài đặt các thư viện C/C++ cần thiết để GraalVM thực hiện liên kết (linking)# ĐÃ THÊM LẠI MAVEN: Cần thiết để chạy lệnh 'mvn'RUN microdnf install -y \
gcc \
gcc-c++ \
zlib-devel \
maven \
bash \
&& microdnf clean all \
&& rm -rf /var/cache/microdnf
# Bước xây dựng: Biên dịch ứng dụng thành executable# Kết quả executable sẽ nằm trong thư mục target/RUN mvn clean package -Pnative
# ----------------------------------------------------------------------# STAGE 2: RUNNER - Image cuối cùng siêu nhỏ gọn (Super-Minimal)# Sử dụng base image 'scratch' (image rỗng) để đạt kích thước nhỏ nhất# CHỈ những gì được COPY từ stage 'builder' mới tồn tại trong image cuối cùng.FROM alpine:latest
# Tải các thư viện C cần thiết từ builder image (glibc, libstdc++)COPY --from=builder /usr/lib64/libz.so.1 /usr/lib64/
COPY --from=builder /usr/lib64/libstdc++.so.6 /usr/lib64/
# Copy các thư viện C cơ sở quan trọng nhất (như glibc)COPY --from=builder /usr/lib64/libc.so.6 /usr/lib64/
COPY --from=builder /usr/lib64/libdl.so.2 /usr/lib64/
COPY --from=builder /usr/lib64/libm.so.6 /usr/lib64/
COPY --from=builder /usr/lib64/libpthread.so.0 /usr/lib64/
COPY --from=builder /usr/lib64/librt.so.1 /usr/lib64/
COPY --from=builder /lib64/ld-linux-x86-64.so.2 /lib64/
# Đặt thư mục làm việc và sao chép executableWORKDIR /app
# Sao chép executable đã được biên dịch từ Stage 1 (builder)COPY --from=builder /app/target/ /app/target/
RUN mkdir -p /home/user/tmp && chmod 777 /home/user/tmp
# Lấy executable và đổi tên thành 'application'# ĐÃ CẬP NHẬT: Sử dụng tên artifact "native-demo-runner"COPY --from=builder /app/target/native-demo /app/application
RUN mkdir -p /home/user/tmp
# Cấu hình cổng mặc định (nếu ứng dụng là web)EXPOSE 8080
# Điểm vào (ENTRYPOINT) để chạy ứng dụng Native Image# Cần set LD_LIBRARY_PATH để runner tìm thấy các thư viện C vừa copy# ĐÃ SỬA CẢNH BÁO: Thay thế cú pháp nối chuỗi để tránh cảnh báo UndefinedVar# 4. Cấu hình RuntimeRUN adduser -D appuser
USER appuser
ENV JAVA_TOOL_OPTIONS="-Djava.io.tmpdir=/home/user/tmp"ENV LD_LIBRARY_PATH=/usr/lib64
ENTRYPOINT ["/app/application"]