From 9f2a8a7f42190de5a078b1bd4232f3ba9a70bdf7 Mon Sep 17 00:00:00 2001 From: Philipp Riegger Date: Thu, 26 May 2022 23:11:10 +0200 Subject: [PATCH] add docker build --- Dockerfile | 19 +++++++++++++++++++ README.md | 17 +++++++++++++++++ go.sum | 0 3 files changed, 36 insertions(+) create mode 100644 Dockerfile create mode 100644 README.md create mode 100644 go.sum diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..05eee44 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,19 @@ +FROM golang:1.18-alpine as builder + +WORKDIR /app + +COPY go.mod ./ +COPY go.sum ./ + +RUN go mod download + +COPY *.go ./ + +RUN CGO_ENABLED=0 go build -o ./go-hello-world + + +FROM scratch + +COPY --from=builder /app/go-hello-world /bin/go-hello-world + +ENTRYPOINT [ "/bin/go-hello-world" ] diff --git a/README.md b/README.md new file mode 100644 index 0000000..3d3426b --- /dev/null +++ b/README.md @@ -0,0 +1,17 @@ +# go-hello-world + +A simple hello-world go application. + +## Building and running the docker image + +### Using nix + + docker load < $(nix-build ci.nix -A docker-image) + docker run --rm -it --name go-hello-world-nix go-hello-world:dev-nix + docker export go-hello-world-nix | tar tf - + +### Using the Dockerfile + + docker build -t go-hello-world:dev-alpine . + docker run --rm -it -p 8000 --name go-hello-world-alpine go-hello-world:dev-alpine + docker export go-hello-world-alpine | tar tf - diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..e69de29 -- 2.45.2