-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile.minimal
More file actions
92 lines (82 loc) · 3.56 KB
/
Dockerfile.minimal
File metadata and controls
92 lines (82 loc) · 3.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# Minimal LFS Docker build for production use
FROM alpine:latest AS builder
# Install necessary tools for processing
RUN apk add --no-cache tar gzip findutils
# Copy LFS source
COPY lfs12/ /lfs-staging/
# Aggressive cleanup for minimal container
RUN cd /lfs-staging && \
# Remove kernel and boot files (not needed in container)
rm -rf boot/* && \
# Remove device files (will be created by Docker)
rm -rf dev/* && \
# Remove mount points content
rm -rf proc/* sys/* tmp/* && \
# Remove lost+found
rm -rf lost+found && \
# Remove documentation and man pages
rm -rf usr/share/man/* usr/share/doc/* usr/share/info/* && \
# Remove locale files except C.UTF-8
find usr/share/locale -mindepth 1 -maxdepth 1 ! -name 'C*' -exec rm -rf {} + && \
# Remove static libraries
find usr/lib lib usr/lib64 lib64 -name "*.a" -delete 2>/dev/null || true && \
# Remove development headers
rm -rf usr/include/* && \
# Remove pkgconfig files
find usr/lib -name "pkgconfig" -type d -exec rm -rf {} + 2>/dev/null || true && \
# Remove libtool files
find . -name "*.la" -delete && \
# Remove Python cache and compiled files
find . -name "__pycache__" -type d -exec rm -rf {} + 2>/dev/null || true && \
find . -name "*.pyc" -delete 2>/dev/null || true && \
find . -name "*.pyo" -delete 2>/dev/null || true && \
# Remove Perl pod files
find . -name "*.pod" -delete 2>/dev/null || true && \
# Remove test directories
find . -name "test" -type d -exec rm -rf {} + 2>/dev/null || true && \
find . -name "tests" -type d -exec rm -rf {} + 2>/dev/null || true && \
# Remove debug symbols
find usr/bin bin usr/sbin sbin usr/lib lib usr/lib64 lib64 -type f -executable -exec strip --strip-unneeded {} + 2>/dev/null || true && \
# Remove unused sbin tools for containers
cd usr/sbin && rm -f *mount* *swap* *fdisk* *mkfs* *fsck* *parted* *cfdisk* *sfdisk* 2>/dev/null || true && \
cd /lfs-staging/sbin && rm -f *mount* *swap* *fdisk* *mkfs* *fsck* *parted* *cfdisk* *sfdisk* 2>/dev/null || true && \
cd /lfs-staging && \
# Remove compiler toolchain - uncomment if you don't need gcc/make in container
# rm -rf usr/bin/gcc* usr/bin/g++* usr/bin/cpp usr/bin/cc usr/bin/c++ && \
# rm -rf usr/bin/make usr/bin/ar usr/bin/ranlib usr/bin/ld usr/bin/as && \
# rm -rf usr/lib/gcc usr/libexec/gcc && \
# Remove large unnecessary binaries
cd usr/bin && rm -f gdb valgrind* strace *tex* && \
# Keep only essential libraries, remove unused ones
cd /lfs-staging && \
# Remove unused kernel modules
rm -rf usr/lib/modules/* 2>/dev/null || true && \
# Remove timezone data except UTC
cd usr/share/zoneinfo && find . -type f ! -name "UTC" ! -name "GMT*" -delete 2>/dev/null || true && \
cd /lfs-staging && \
# Create essential directories
mkdir -p proc sys tmp dev run var/tmp var/run
# Final stage - create minimal LFS container
FROM scratch
# Copy only the cleaned LFS system
COPY --from=builder /lfs-staging/ /
# Set minimal environment variables
ENV PATH="/usr/bin:/bin:/usr/sbin:/sbin"
ENV TERM=xterm
ENV HOME=/root
ENV USER=root
ENV SHELL=/bin/bash
ENV LC_ALL=C.UTF-8
# Set working directory
WORKDIR /root
# Minimal health check
HEALTHCHECK --interval=60s --timeout=5s --start-period=10s --retries=2 \
CMD /bin/test -f /bin/bash || exit 1
# Add minimal labels
LABEL maintainer="LFS Builder" \
description="Minimal Linux From Scratch 12 Container" \
version="12.0-minimal" \
size="minimal" \
architecture="x86_64"
# Default command
CMD ["/bin/bash"]