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

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

  • go的web代码
package main

import(
    "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:alpine
workdir /app 
copy . /app/
# run go build main.go
# expose 8080
# entrypoint ["./main"]
expose 8080
entrypoint go run main.go
  • 感悟
    • run和entrypoint,都可以执行命令,可以不用写中括号

猜你喜欢

转载自www.cnblogs.com/MyUniverse/p/11530983.html