Skip to content

appleboy/docker-multi-stage-build

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

Multi-Stage Docker Builds for Creating Tiny Go Images

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published