我按照使用 BusyBox Docker 图像构建应用程序:自定义图像的完整指南。
文件
# Use busybox as the base image
FROM busybox
# Copy over the executable file
COPY ./server /home/server
# Run the executable file
CMD /home/server
网络服务器
package main
import (
"fmt"
"net/http"
)
func handler(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Hello World!")
}
func main() {
http.HandleFunc("/", handler)
fmt.Println("Server running...")
http.ListenAndServe(":8080", nil)
}
编译为可执行server文件GOOS=linux GOARCH=amd64 go build server.go
构建基于图像的busybox
[mymachine@localhost tmp]$ docker image build -t go-server .
Sending build context to Docker daemon 6.562MB
Step 1/3 : FROM busybox
---> beae173ccac6
Step 2/3 : COPY ./server /home/server
---> Using cache
---> 9d58653768ea
Step 3/3 : CMD /home/server
---> Running in 994cce171c11
Removing intermediate container 994cce171c11
---> 38996797b6d8
Successfully built 38996797b6d8
Successfully tagged go-server:latest
*当运行容器时,server找不到。我对此一无所知。
它不支持网络服务器可执行文件吗?
江户川乱折腾
相关分类