尝试部署Web应用程序时出现以下错误:
错误-网站XXX的容器XXX_0在预期的期限内未启动。经过的时间= 1800.4463925秒
我正在尝试部署节点应用程序。通过.deployment文件使用自动部署。.deployment文件如下所示:
# 1. KuduSync
if [[ "$IN_PLACE_DEPLOYMENT" -ne "1" ]]; then
"$KUDU_SYNC_CMD" -v 50 -f "$DEPLOYMENT_SOURCE" -t "$DEPLOYMENT_TARGET" -n "$NEXT_MANIFEST_PATH" -p "$PREVIOUS_MANIFEST_PATH" -i ".git;.hg;
.deployment;deploy.sh"
exitWithMessageOnError "Kudu Sync failed"
fi
# 2. Select node version
selectNodeVersion
# 3. Install npm packages for root directory
if [ -e "$DEPLOYMENT_TARGET/package.json" ]; then
cd "$DEPLOYMENT_TARGET"
# echo "Running $NPM_CMD install --production for root directory"
# eval $NPM_CMD install --production
echo "Running $NPM_CMD install --production for root directory"
eval $NPM_CMD install
exitWithMessageOnError "npm failed"
##################
echo Building App...
eval $NPM_CMD run build
##################
echo Starting App...
# eval $NPM_CMD run start
# cd - > /dev/null
fi
#####################################################################################
echo "Finished successfully."
package.json文件具有以下脚本:
"scripts": {
"dev": "node server.js",
"build": "next build",
"start": "echo 'work!!' && NODE_ENV=production && node server.js"
}
而server.js如下:
const {
createServer
} = require('http')
const next = require('next')
const app = next({
dev: process.env.NODE_ENV !== 'production'
})
const routes = require('./routes')
const handler = routes.getRequestHandler(app)
console.log("HEYYYY");
// Without express
app.prepare()
.then(() => {
console.log("Ready on Localhost:80!!!");
createServer(handler)
.listen(80, (err) => {
if (err) throw err;
console.log("Ready on Localhost:80");
});
})
我从研究中收集到的是:
解决(1)我将WEBSITES_CONTAINER_START_TIME_LIMIT设置为1800(最大值)
为了解决(2),我将WEBSITES_PORT(在应用程序设置中)设置为“ 80”以暴露该端口。(根据文档)
还有其他我应该尝试的事情吗?
PS默认docker日志文件输出以下内容:
2018-10-15T14:32:59.946431939Z > XXX@1.0.0 start /home/site/wwwroot
2018-10-15T14:32:59.946455839Z > echo 'work!!' && NODE_ENV=production && node server.js
2018-10-15T14:32:59.946462839Z
2018-10-15T14:33:00.249554126Z work!!
2018-10-15T14:34:41.634101502Z HEYYYY
2018-10-15T14:35:38.838555689Z DONE Compiled successfully in 48099ms14:35:38
2018-10-15T14:35:38.838868291Z
2018-10-15T14:35:39.406086808Z Ready on Localhost:80!!!
2018-10-15T14:35:39.460029162Z Ready on Localhost:80
对我来说,同时设置
-Port 80
和-WEBSITES_PORT 80
在Azure App Service Deploy
任务中,App Settings
在蔚蓝的DEVOPS节帮助。它使docker从端口80而不是8000开始。这是该任务的应用程序设置用法示例。