入门案例
创建Go程序:main.go文章源自菜鸟学院-https://www.cainiaoxueyuan.com/ymba/30708.html
package main import ( "fmt" ) func main() { fmt.Println("使用Docker运行Go程序") }
文章源自菜鸟学院-https://www.cainiaoxueyuan.com/ymba/30708.html
创建文件:Dockerfile文章源自菜鸟学院-https://www.cainiaoxueyuan.com/ymba/30708.html
FROM golang:alpine RUN mkdir /app COPY ./ /app WORKDIR /app RUN go build -o /app/main main.go ENTRYPOINT ["/app/main"]
文章源自菜鸟学院-https://www.cainiaoxueyuan.com/ymba/30708.html
构建镜像:文章源自菜鸟学院-https://www.cainiaoxueyuan.com/ymba/30708.html
docker build -t hello_go:v1 .
文章源自菜鸟学院-https://www.cainiaoxueyuan.com/ymba/30708.html
删除镜像(可选):文章源自菜鸟学院-https://www.cainiaoxueyuan.com/ymba/30708.html
docker rmi hello_go:v1
文章源自菜鸟学院-https://www.cainiaoxueyuan.com/ymba/30708.html
运行镜像:文章源自菜鸟学院-https://www.cainiaoxueyuan.com/ymba/30708.html
docker run hello_go:v1文章源自菜鸟学院-https://www.cainiaoxueyuan.com/ymba/30708.html