简体   繁体   English

无法将 golang 应用程序部署到 Azure 应用程序服务容器

[英]Unable to deploy golang app to Azure app services container

I've tried a lot of Dockerfile samples to build my golang app, they're working fine running on local.我已经尝试了很多 Dockerfile 示例来构建我的 golang 应用程序,它们在本地运行良好。

Here is the last one Dockerfile I tried这是我试过的最后一个 Dockerfile

FROM golang:alpine
EXPOSE 80
RUN  mkdir -p /app
WORKDIR /app
COPY . .
RUN go mod download
RUN go build -o app
ENTRYPOINT ["./app"]

I push my image to my Azure Container registry and use it via App service(linux) Deployment Center.我将我的图像推送到我的 Azure 容器注册表并通过应用服务(linux)部署中心使用它。

errors I got:我得到的错误:

在此处输入图像描述

You can try to solve your problem in the following two ways.您可以尝试通过以下两种方式解决您的问题。

  1. According to your screenshot, you can add a startup command to the dockerfile.根据您的屏幕截图,您可以向 dockerfile 添加启动命令。

    Reference link:参考链接:

    1. How To Deploy a Go Web Application with Docker 1. 如何使用 Docker 部署 Go Web 应用程序

    2. Changing RUN to CMD stops the container from working 2. 将 RUN 更改为 CMD 会使容器停止工作

  2. Make sure your files have been posted to the scm website.确保您的文件已发布到 scm 网站。 After under wwwroot, use the startup command to start your application.在 wwwroot 下之后,使用启动命令启动您的应用程序。

     go run main.go

    Reference link:参考链接:

    Step by step guide to deploy Golang Application on Azure Web App 在 Azure Web App 上部署 Golang 应用程序的分步指南

I modified the port listening to 80 (App service default WEBSITE_PORT)我修改了监听80的端口(App服务默认WEBSITE_PORT)

add ENV to Dockerfile将 ENV 添加到 Dockerfile

ENV GOOS=linux GOARCH=amd64

Change Entrypoint更改入口点

ENTRYPOINT [/app/app]

finally works.终于奏效了。

reference 参考

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM