我在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/