git - 从git repo Docker化go应用程序

标签 git docker go

我在git中有一个main.go应用程序,我需要创建docker文件并在kubernetes集群中运行应用程序。

我创建了docker文件,但不确定它是否正确,
如何从git将main.go添加到docker?

假设main.go在git的一个repo中:

我在同一个A存储库中创建了一个docker文件(这是我的docker文件):

#  base image for Go
FROM golang:latest

RUN mkdir /app


ADD . /app

# Set the Current Working Directory inside the container

WORKDIR /app


# Build the Go app
RUN go get github.com/gorilla/mux
RUN go build -o app/main



#COPY / ./

# Command to run the executable

CMD ["/app/main"]

我创建了图像->我怎么知道我在做什么呢?
请帮忙!

最佳答案

这应该做(我也重构了您的Dockerfile)。

引用此-https://docs.docker.com/develop/develop-images/dockerfile_best-practices/

#  base image for Go
FROM golang:latest

RUN mkdir /app

# Set the Current Working Directory inside the container
WORKDIR /app

ADD . /app

# Build the Go app
RUN go get github.com/gorilla/mux && go build -o app/main

ENTRYPOINT ["/app/main"]

您可以通过doind运行图像
docker run -d <image>

关于git - 从git repo Docker化go应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59776629/

相关文章:

git - 如何使用cmd创建文件?

从注册表获取 dockerfile 的 Docker 命令

docker - 由于Docker永久卷,在GitLab顶部构建的管道失败

go - 使用 Golang 启动 D-Bus 服务

git - 将本地 GIT 存储库添加到 Gogs Docker 容器

git 计数阶段索引中的文件

docker - Docker AWS端口

go - SendGrid SMTP 电子邮件不会发送到 Go 中的抄送和密件抄送地址

http - 解密后的反向代理服务文件

java - 将 Github 项目导入 Eclipse 时出错?