1.源码
package main
import (
"fmt"
"net/http"
)
func main() {
http.HandleFunc("/", home)
http.ListenAndServe(":80", nil)
}
func home(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "welcome to golang world")
}
dockerfile
FROM daocloud.io/library/centos
USER root
RUN mkdir /app
WORKDIR /app
ADD . /app
EXPOSE 80
CMD ["chmod +x helloworld"]
CMD ["./helloworld"]
2.源码编译在mac环境需要交叉编译
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o helloworld helloworld.go
3.docker执行需要暴露端口
docker run -p 801:80 helloworld
有疑问加站长微信联系(非本文作者)