Skip to content

koalacxr/buildrundocker_example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

编译并运行一个比较小的 golang Docker Image Build Status

第一步编写App项目

package main

import "fmt"

func main() { fmt.Println("Hello world!") }

第二步编写Dockerfile文件

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

FROM alpine WORKDIR /app COPY --from=build-env /src/goapp /app/ ENTRYPOINT ./goapp

第三步执行app_build_run.sh脚本

大部分项目只要修改app_build_run.sh脚本中imagename变量就行了

imagename="kevin/hello"

docker build -t ${imagename} . docker rmi $(docker images -q -f dangling=true)

echo "######################################################################################" echo "#################################Successed############################################" echo "Show current docker images:" docker images

echo "######################################################################################" echo "#################################Running......########################################" echo "Application running:" docker run -ti --rm ${imagename}

执行结果如下,只有6MB, 不会大200多MB了

image

About

Build and Run a smaller golang docker image

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages