golang编译和docker执行

2018-10-23  本文已影响92人  heliping_peter

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
ADD . /app
EXPOSE 80
WORKDIR /app/helloworld
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
上一篇下一篇

猜你喜欢

热点阅读