https://github.com/janritter/minimal-golang-docker-image
This repo shows how to build minimal (distroless) images for Golang applications and compares image sizes of the different options
https://github.com/janritter/minimal-golang-docker-image
Last synced: 3 months ago
JSON representation
This repo shows how to build minimal (distroless) images for Golang applications and compares image sizes of the different options
- Host: GitHub
- URL: https://github.com/janritter/minimal-golang-docker-image
- Owner: janritter
- Created: 2022-05-15T14:38:33.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2022-09-25T22:43:04.000Z (over 2 years ago)
- Last Synced: 2023-03-02T19:16:18.287Z (over 2 years ago)
- Language: Makefile
- Homepage:
- Size: 3.91 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Minimal Golang Docker Image
This repo shows how to build minimal (distroless) images for Golang applications and compares image sizes of the different options.
Good writeups on advantages / disadvantages of distroless images:
- [Stop using Alpine Docker images](https://medium.com/inside-sumup/stop-using-alpine-docker-images-fbf122c63010)
- [Docker Distroless PoC](https://github.com/erickduran/docker-distroless-poc)## Example application
Our go application for this experiment is really basic, it only requests https://google.com and logs the response.
## Builds
### Alpine Build
This build uses an alpine base image.
```bash
make build-alpine
```### Distroless Build
This build uses the [Google distroless](https://github.com/GoogleContainerTools/distroless) image.
```bash
make build-distroless
```### Scratch Build
```bash
make build-scratch
```Our application requires ca certificates to validate the google.com certificate when calling, without ca certificates our application shows the following error:
```bash
2022/05/15 14:39:31 Get "https://google.com": x509: certificate signed by unknown authority
```To fix this error we copy the ca certificates in our multi step build from the alpine image into our scratch image
## Size comparison
To list all images after building, run the following command:
```bash
make list-images
``````bash
REPOSITORY TAG IMAGE ID SIZE
minimal-golang-image scratch cb5b0ddfa5eb 4.66MB
minimal-golang-image distroless 413ba53147b8 6.82MB
minimal-golang-image alpine bba979b9524a 10.5MB
```The smallest image is our multi step scratch image, followed by the distroless build, the biggest image in our comparison is the alpine one.