forked from freudenreichan/EinfuehrungInDocker_Pipeline2
42 lines
835 B
Docker
42 lines
835 B
Docker
# Aufgabe 1
|
|
FROM alpine:latest AS builder
|
|
|
|
# C-Compiler + No-Cache
|
|
RUN apk add --no-cache build-base
|
|
|
|
# Arbeitsverzeichnis
|
|
WORKDIR /app
|
|
|
|
# Code hineinkopieren
|
|
COPY . .
|
|
|
|
# Kompilieren
|
|
RUN gcc -o deployment deployment.c
|
|
|
|
# Runtime
|
|
|
|
FROM alpine:latest
|
|
|
|
# Aufgabe 2.2.1 Non-Root User
|
|
RUN addgroup -S appgroup && adduser -S appuser -G appgroup
|
|
|
|
# Arbeitsverzeichnis
|
|
WORKDIR /app
|
|
|
|
COPY --from=builder /app/deployment .
|
|
|
|
# User Rechte
|
|
RUN mkdir /output && chown appuser:appgroup /output
|
|
|
|
# Aufgabe 2.2.2 Container als normaler User
|
|
USER appuser
|
|
|
|
# Aufgabe 5 Datavolume mounten
|
|
VOLUME ["/output"]
|
|
|
|
# Aufgabe 6 Healthcheck
|
|
HEALTHCHECK --interval=30s --timeout=5s --start-period=5s --retries=3 \
|
|
CMD test -f /output/output.txt || exit 1
|
|
|
|
# Startbefehl
|
|
CMD ["sh", "-c", "./deployment 10 > /output/output.txt && tail -f /output/output.txt"] |