All Projects → appleboy → docker-multi-stage-build

appleboy / docker-multi-stage-build

Licence: MIT license
Multi-Stage Docker Builds for Creating Tiny Go Images

Programming Languages

Makefile
30231 projects
go
31211 projects - #10 most used programming language

Labels

docker-multi-stage-build

Multi-Stage Docker Builds for Creating Tiny Go Images

Single-stage build

See the Dockerfile.alpine

FROM golang:alpine
WORKDIR /app
ADD . /app
RUN cd /app && go build -o app
ENTRYPOINT ./app

build and run as the following command.

$ docker build -f Dockerfile.alpine -t appleboy/go-app .
$ docker run --rm appleboy/go-app

258 MB, just for our single little Go binary.

Multi-Stage build

See the Dockerfile.alpine

# build stage
FROM golang:alpine AS build-env
ADD . /src
RUN cd /src && go build -o app

# final stage
FROM alpine
WORKDIR /app
COPY --from=build-env /src/app /app/
ENTRYPOINT ./app

build and run as the following command.

$ docker build -t appleboy/go-app .
$ docker run --rm appleboy/go-app

6.35 MB. Much better.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].