[英]Application run failed after deploying dockerized image on Azure App Service
I am trying to deploy dockerized React JS application (uses ngnix) on MS Azure App Service (Web application as Container/Web App).我正在尝试在 MS Azure 应用服务(Web 应用程序作为容器/Web 应用程序)上部署 dockerized React JS 应用程序(使用 ngnix)。 Using Azure Container Registry for the same.同样使用 Azure 容器注册表。
Here is my Dockerfile这是我的 Dockerfile
FROM node:14.17.0 as build
WORKDIR /app
ENV PATH /app/node_modules/.bin:$PATH
COPY package.json ./
COPY package-lock.json ./
RUN npm ci --silent
RUN npm install react-scripts -g --silent
COPY . .
RUN npm run build
#prepare nginx
FROM nginx:stable-alpine
COPY --from=build /app/build /usr/share/nginx/html
#fire up nginx
EXPOSE 80
CMD ["nginx","-g","daemon off;"]
Able to run image as container on local machine and working perfectly.能够在本地机器上将图像作为容器运行并完美运行。
docker run -itd --name=ui-container -p 80:80 abc.azurecr.io:latest
But problem starts after running the image on Azure App Service/ Container Service due to it is not able to ping the port.但是在 Azure App Service/Container Service 上运行图像后问题开始了,因为它无法 ping 通端口。 ERROR - Container didn't respond to HTTP pings on port: 80, failing site start.错误 - 容器未响应端口 80 上的 HTTP ping,站点启动失败。 See container logs for debugging查看容器日志进行调试
This is the docker run command available on App service logs这是应用程序服务日志上可用的 docker run 命令
docker run -d --expose=80 --name id_0_f8823503 -e WEBSITES_ENABLE_APP_SERVICE_STORAGE=false -e WEBSITES_PORT=80 -e WEBSITE_SITE_NAME=id -e WEBSITE_AUTH_ENABLED=False -e WEBSITE_ROLE_INSTANCE_ID=0 -e WEBSITE_HOSTNAME=id.azurewebsites.net -e WEBSITE_INSTANCE_ID=af26eeb17400cdb1a96c545117762d0fdf33cf24e01fb4ee2581eb015d557e50 -e WEBSITE_USE_DIAGNOSTIC_SERVER=False i.azurecr.io/ivoyant-datamapper
I see the reason is there is no -p 80:80 found in above docker run command.我知道原因是在上面的 docker run 命令中没有找到 -p 80:80 。 I have tried multiple approaches to fix this but nothing worked for me.我尝试了多种方法来解决这个问题,但对我没有任何帮助。 Tried adding key: PORT value: 80 in configuration app settings key: WEBSITES_PORT value: 80 in configuration app settings尝试添加密钥:PORT 值:配置应用程序设置中的 80 密钥:WEBSITES_PORT 值:配置应用程序设置中的 80
App Service listens on port 80/443 and forwards traffic to your container on port 80 by default.默认情况下,应用服务侦听端口 80/443 并将流量转发到端口 80 上的容器。 If your container is listening on port 80, no need to set the WEBSITES_PORT application setting.如果您的容器正在侦听端口 80,则无需设置WEBSITES_PORT应用程序设置。 The -p 80:80 parameter is not needed.不需要-p 80:80参数。
You would set WEBSITES_PORT to the port number of your container only if it listens on a different port number.只有当它侦听不同的端口号时,您才可以将WEBSITES_PORT设置为容器的端口号。
Now, why does App Service reports that error?现在,为什么 App Service 会报告该错误? It might be that your app fails when starting.可能是您的应用程序在启动时失败。 Try enabling the application logs to see if you'll get more info.尝试启用应用程序日志以查看您是否会获得更多信息。
Replaced已更换
FROM node:14.17.0 as build
with和
FROM node:19-alpine as build
Application was deployed successfully in Azure with success response.应用程序已在 Azure 中成功部署并获得成功响应。 Usage of non alpine image caused the issue in Azure App Service.使用非高山图像导致 Azure 应用服务出现问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.