How to dockerize Go application
Introduction
When you develop an application then you need to dockerize your application.
Guide
Create an application, say Hello world
under ./cmd/test/main.go
.
1 | go mod init test |
1 | package main |
Create Dockerfile
to dockerize application.
1 | FROM golang:alpine AS builder |
Build docker image following command.
1 | docker build -t test:latest . |
Run docker image following command.
1 | docker run -it --rm test:latest |
Then should print Hello world
on terminal.
Conclusion
The multiple stage is important in Dockerfile
. It can optimize size of docker image.