Azure Linux Web 应用程序:错误 - 容器未响应端口 7007 上的 HTTP ping,站点启动失败

问题描述 投票:0回答:1

我有一个 Azure Web 应用程序,运行来自 Azure 容器注册表的映像。容器启动正常,但站点无法启动。

我在端口 7007 上运行它并设置了环境变量 WEBSITES_PORT=7007。

我的应用程序配置具有在端口 7007 上运行的正确设置,并且我已在 Dockerfile 中公开了该端口。

Dockerfile 代码:https://backstage.io/docs/deployment/docker/#multi-stage-build

这是完整的错误:

ERROR - Container for site has exited, failing site start
  Ok
2024-06-13T17:05:48.847
ERROR - Container didn't respond to HTTP pings on port: 7007, failing site start. See container logs for debugging.
  Ok
2024-06-13T17:05:48.849
INFO  - Stopping site because it failed during startup.

该站点在端口 7007 上运行没有任何问题,但大约两周前开始出现故障。我很高兴分享更多代码或上下文。谢谢!

azure docker dockerfile azure-web-app-service azure-web-app-for-containers
1个回答
0
投票

我按照您提供的文档创建了一个后台应用程序,并通过 Azure 容器注册表成功部署到 azure 应用程序服务。

为了设置多阶段 docker 构建,我更新了

dockerfile
.dockerignore
文件,如下所示。

Dockerfile:

FROM node:18-bookworm-slim AS packages
WORKDIR /app
COPY package.json yarn.lock ./
COPY packages packages
COPY plugins plugins
RUN find packages \! -name "package.json" -mindepth 2 -maxdepth 2 -exec rm -rf {} \+
FROM node:18-bookworm-slim AS build
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
    --mount=type=cache,target=/var/lib/apt,sharing=locked \
    apt-get update && \
    apt-get install -y --no-install-recommends python3 g++ build-essential && \
    yarn config set python /usr/bin/python3
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
    --mount=type=cache,target=/var/lib/apt,sharing=locked \
    apt-get update && \
    apt-get install -y --no-install-recommends libsqlite3-dev
USER node
WORKDIR /app
COPY --from=packages --chown=node:node /app .
RUN --mount=type=cache,target=/home/node/.cache/yarn,sharing=locked,uid=1000,gid=1000 \
    yarn install --frozen-lockfile --network-timeout 600000
COPY --chown=node:node . .
RUN yarn tsc
RUN yarn --cwd packages/backend build
RUN mkdir packages/backend/dist/skeleton packages/backend/dist/bundle \
    && tar xzf packages/backend/dist/skeleton.tar.gz -C packages/backend/dist/skeleton \
    && tar xzf packages/backend/dist/bundle.tar.gz -C packages/backend/dist/bundle
FROM node:18-bookworm-slim
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
    --mount=type=cache,target=/var/lib/apt,sharing=locked \
    apt-get update && \
    apt-get install -y --no-install-recommends python3 g++ build-essential && \
    yarn config set python /usr/bin/python3
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
    --mount=type=cache,target=/var/lib/apt,sharing=locked \
    apt-get update && \
    apt-get install -y --no-install-recommends libsqlite3-dev
USER node
WORKDIR /app
COPY --from=build --chown=node:node /app/yarn.lock /app/package.json /app/packages/backend/dist/skeleton/ ./
RUN --mount=type=cache,target=/home/node/.cache/yarn,sharing=locked,uid=1000,gid=1000 \
    yarn install --frozen-lockfile --production --network-timeout 600000
COPY --from=build --chown=node:node /app/packages/backend/dist/bundle/ ./
COPY --chown=node:node app-config.yaml ./
ENV NODE_ENV production
CMD ["node", "packages/backend", "--config", "app-config.yaml"]

.dockerignore:

dist-types
node_modules
packages/*/dist
packages/*/node_modules
plugins/*/dist
plugins/*/node_modules

我运行了以下命令来构建和运行后台应用程序。

docker image build -t backstage .
docker run -it -p 7007:7007 backstage

我使用以下命令将 docker 映像推送到 Azure 容器注册表。

az acr login -n <container-registry>
docker tag <image-name> <container-registry>.azurecr.io/<image-name>:<tag>
docker push <container-registry>.azurecr.io/<image-name>:<tag>

创建 Azure Web 应用程序时,选择发布选项作为容器 -> Azure 容器注册表。

当我只在环境变量中提到端口时,我遇到了同样的问题。

因此,请确保您的端口设置为

7007
,如下所示。 enter image description here

部署后输出:

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.