Optimize Dockerfile
This commit is contained in:
parent
084f033c87
commit
68bdfc3a73
38
Dockerfile
38
Dockerfile
@ -1,9 +1,8 @@
|
||||
# Base-Image
|
||||
FROM ubuntu:latest
|
||||
# ---------- Build Stage ----------
|
||||
FROM alpine:latest AS build
|
||||
|
||||
# Pakete installieren
|
||||
RUN apt-get update
|
||||
RUN apt-get install -y build-essential gcc curl vim net-tools
|
||||
RUN apk add --no-cache build-base
|
||||
|
||||
# Arbeitsverzeichnis setzen
|
||||
WORKDIR /app
|
||||
@ -14,9 +13,30 @@ COPY . .
|
||||
# Code kompilieren
|
||||
RUN gcc -o deployment deployment.c
|
||||
|
||||
# Verzeichnis für Ausgabe anlegen
|
||||
RUN mkdir /output
|
||||
|
||||
# Ausgabe wird ins Container-Dateisystem geschrieben
|
||||
ENTRYPOINT ["/bin/bash", "-c"]
|
||||
CMD ["./deployment 10 > /output/output.txt && tail -f /output/output.txt"]
|
||||
# ---------- Runtime Stage ----------
|
||||
FROM alpine:latest
|
||||
|
||||
# Arbeitsverzeichnis setzen
|
||||
WORKDIR /app
|
||||
|
||||
# Benutzer ohne root-Rechte anlegen
|
||||
RUN adduser -D appuser
|
||||
|
||||
# kompiliertes Programm kopieren
|
||||
COPY --from=build /app/deployment .
|
||||
|
||||
# Verzeichnis für Ausgabe anlegen
|
||||
RUN mkdir /output && chown appuser /output
|
||||
|
||||
# Datavolume definieren
|
||||
VOLUME ["/output"]
|
||||
|
||||
# Benutzer wechseln
|
||||
USER appuser
|
||||
|
||||
# HEALTHCHECK
|
||||
HEALTHCHECK CMD test -f /app/deployment || exit 1
|
||||
|
||||
# Ausgabe wird ins Datavolume geschrieben
|
||||
CMD ["sh", "-c", "./deployment 10 > /output/output.txt && tail -f /output/output.txt"]
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user