失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > docker中使用golang:alpine镜像制作开启goweb的dockerfile

docker中使用golang:alpine镜像制作开启goweb的dockerfile

时间:2020-12-16 21:13:15

相关推荐

docker中使用golang:alpine镜像制作开启goweb的dockerfile

docker中使用golang:alpine镜像制作开启goweb的dockerfile

go的web代码

package mainimport("net/http""fmt")func main(){fmt.Println("开启后端")http.HandleFunc("/Hello",PrintHello)err:=http.ListenAndServe(":8080",nil)if err==nil{fmt.Println("开启8080端口")}}func PrintHello(w http.ResponseWriter, r *http.Request){if r.Method!="GET"{return}fmt.Fprint(w,"hello world")}

dockerfile文件

from golang:alpineworkdir /app copy . /app/# run go build main.go# expose 8080# entrypoint ["./main"]expose 8080entrypoint go run main.go

感悟 run和entrypoint,都可以执行命令,可以不用写中括号

如果觉得《docker中使用golang:alpine镜像制作开启goweb的dockerfile》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。