【发布时间】:2022-12-10 16:08:25
【问题描述】:
我关注Using the BusyBox Docker Image for Building Applications : A Complete Guide 定制图片。
文件
# 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。我我对此一无所知。
[mymachine@localhost tmp]$ docker run -p 8080:8080 --rm -it go-server ls -l /home
total 6408
-rwxrwxr-x 1 root root 6559402 Oct 13 19:53 server
[mymachine@localhost tmp]$ docker run -p 8080:8080 --rm -it go-server
/bin/sh: /home/server: not found
但它适用于此应用程序
package main
import "fmt"
func main() {
fmt.Println("hello world")
}
它不支持网络服务器可执行文件吗?
docker: executable file not found in $PATH 没有帮助
有什么解决办法吗?
【问题讨论】:
标签: docker go dockerfile