From 5226a19d9c806af66fd18ce1dd20cbc49196a79d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Gl=C3=A4=C3=9Fle?= Date: Thu, 10 Dec 2020 00:11:34 +0100 Subject: [PATCH] Build docker image using multi-stage build This further decreases the image size to 14.6MB. --- Dockerfile | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/Dockerfile b/Dockerfile index d03dfef..eb34f16 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,16 +1,11 @@ -FROM alpine:3.12 - -ENV URL=http://localhost:8080 - +# builder image: +FROM alpine:3.12 as build ARG build_deps="go git" ARG runtime_deps="dumb-init" -ARG user_id=1000 COPY . /go/src/github.com/elisescu/tty-proxy - RUN apk update && \ apk add -u $build_deps $runtime_deps && \ - adduser -D -H -h / -u $user_id tty-proxy && \ cd /go/src/github.com/elisescu/tty-proxy && \ GOPATH=/go go get github.com/go-bindata/go-bindata/... && \ GOPATH=/go /go/bin/go-bindata --prefix static -o gobindata.go static/* && \ @@ -19,9 +14,17 @@ RUN apk update && \ rm -r /go && \ apk del $build_deps +# runtime image: +FROM alpine:3.12 +ARG user_id=1000 +RUN adduser -D -H -h / -u $user_id tty-proxy + EXPOSE 8080 EXPOSE 3456 USER tty-proxy +ENV URL=http://localhost:8080 ENTRYPOINT ["/usr/bin/dumb-init", "--"] CMD ["/bin/sh", "-c", "/usr/bin/tty-proxy --front-address :8080 --back-address :3456 -url $URL"] + +COPY --from=build /usr/bin/dumb-init /usr/bin/tty-proxy /usr/bin/