https://github.com/appleboy/docker-multi-stage-build
Multi-Stage Docker Builds for Creating Tiny Go Images
https://github.com/appleboy/docker-multi-stage-build
docker golang
Last synced: 9 months ago
JSON representation
Multi-Stage Docker Builds for Creating Tiny Go Images
- Host: GitHub
- URL: https://github.com/appleboy/docker-multi-stage-build
- Owner: appleboy
- License: mit
- Created: 2017-04-29T09:38:11.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2017-04-29T11:24:18.000Z (over 8 years ago)
- Last Synced: 2025-04-10T08:28:52.466Z (9 months ago)
- Topics: docker, golang
- Language: Makefile
- Size: 3.91 KB
- Stars: 24
- Watchers: 3
- Forks: 7
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# docker-multi-stage-build
[Multi-Stage][1] Docker Builds for Creating Tiny Go Images
[1]:https://github.com/moby/moby/pull/32063
## Single-stage build
See the [Dockerfile.alpine](./Dockerfile.alpine)
```dockerfile
FROM golang:alpine
WORKDIR /app
ADD . /app
RUN cd /app && go build -o app
ENTRYPOINT ./app
```
build and run as the following command.
```sh
$ 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](./Dockerfile.alpine)
```dockerfile
# 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.
```sh
$ docker build -t appleboy/go-app .
$ docker run --rm appleboy/go-app
```
**6.35 MB**. Much better.