-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile.optimized
More file actions
59 lines (48 loc) · 1.57 KB
/
Dockerfile.optimized
File metadata and controls
59 lines (48 loc) · 1.57 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
# Multi-stage LFS Docker build for smaller images
FROM alpine:latest AS builder
# Install necessary tools for processing
RUN apk add --no-cache tar gzip
# Copy LFS source
COPY lfs12/ /lfs-staging/
# Clean up unnecessary files for container use
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 && \
# Create essential directories
mkdir -p proc sys tmp dev && \
# Remove some unnecessary sbin tools for containers
find usr/sbin sbin -name "*mount*" -delete 2>/dev/null || true && \
find usr/sbin sbin -name "*swap*" -delete 2>/dev/null || true
# Final stage - create the LFS container
FROM scratch
# Copy the cleaned LFS system
COPY --from=builder /lfs-staging/ /
# Set environment variables
ENV PATH="/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/sbin"
ENV TERM=xterm-256color
ENV HOME=/root
ENV USER=root
ENV SHELL=/bin/bash
ENV LC_ALL=C.UTF-8
ENV LANG=C.UTF-8
# Create necessary runtime directories
RUN mkdir -p /tmp /var/tmp /run /var/run
# Set working directory
WORKDIR /root
# Health check
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
CMD /bin/test -f /bin/bash || exit 1
# Add labels
LABEL maintainer="LFS Builder" \
description="Linux From Scratch 12 Container" \
version="12.0" \
size="optimized" \
architecture="x86_64"
# Default command
CMD ["/bin/bash"]