使用Docker运行Go程序入门案例

2023-02-0410:50:19编程语言入门到精通Comments710 views字数 287阅读模式

入门案例

创建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
  • 本站内容整理自互联网,仅提供信息存储空间服务,以方便学习之用。如对文章、图片、字体等版权有疑问,请在下方留言,管理员看到后,将第一时间进行处理。
  • 转载请务必保留本文链接:https://www.cainiaoxueyuan.com/ymba/30708.html

Comment

匿名网友 填写信息

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定