我正在尝试使用 nginx - azure 应用程序服务 w/ docker-compose 设置一个简单的 nginx 端点。 我可以在本地运行 docker-compose,这工作得很好,但在 azure 应用程序服务中我遇到了基本的应用程序错误。
Docker-Compose Azure App Configuration
version: '2.2'
services:
loadbalancer:
image: .../loadbalancertest
networks:
- mynetwork
ports:
- 80:8090
tty: true
networks:
mynetwork:
driver: bridge
Dockerfile
FROM nginx:alpine
RUN apk update && apk upgrade && apk add bash curl && apk add openssl;
RUN rm /etc/nginx/conf.d/default.conf
COPY nginx.conf /etc/nginx/conf.d/default.conf
COPY index.html /usr/share/nginx/html
RUN mkdir /usr/nginx
RUN openssl req -x509 -nodes -days 3650 -subj "/C=CA/ST=QC/O=Company, Inc./CN=isiGov.gov" -addext "subjectAltName=DNS:isiGov.gov" -newkey rsa:2048 -keyout /usr/nginx/ssl.key -out /usr/nginx/ssl.crt;
EXPOSE 8090
# Start Nginx
CMD ["nginx", "-g", "daemon off;"]
index.html
<!DOCTYPE html>
<html>
<head>
<title>Hello World</title>
</head>
<body>
<h1>Hello World</h1>
<p>Welcome to your first HTML document!</p>
</body>
</html>
error_log ./error.log warn;
server {
server_name _;
listen 8090 ssl;
underscores_in_headers on;
ssl_certificate /usr/nginx/ssl.crt;
ssl_certificate_key /usr/nginx/ssl.key;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
try_files $uri $uri/ /index.html;
}
}
events { worker_connections 1024; }
tail log from azure app docker files:
2024-07-28T15:41:39.048Z INFO - docker run -d -p 7865:80 --name isiworkflowwizard-dev_loadbalancer_0_3e6c9a02 -e WEBSITES_ENABLE_APP_SERVICE_STORAGE=false -e WEBSITE_SITE_NAME=ISIWorkflowWizard-dev -e WEBSITE_AUTH_ENABLED=False -e WEBSITE_ROLE_INSTANCE_ID=0 -e WEBSITE_HOSTNAME=isiworkflowwizard-dev.azurewebsites.net -e WEBSITE_INSTANCE_ID=d2fb0ec5c9f8c5efa098c8e3693f48097d07c3d7fa038e9dad975abf2e74aa53 bprassistantregistry.azurecr.io/loadbalancertest
2024-07-28T15:41:39.048Z INFO - Logging is not enabled for this container.
Please use https://aka.ms/linux-diagnostics to enable logging to see container logs here.
2024-07-28T15:45:29.724Z ERROR - multi-container unit was not started successfully
2024-07-28T15:45:30.706Z INFO - Container logs from isiworkflowwizard-dev_loadbalancer_0_3e6c9a02 = 2024-07-28T15:41:40.755987733Z /docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
2024-07-28T15:41:40.756020084Z /docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
2024-07-28T15:41:40.759056350Z /docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
2024-07-28T15:41:40.773221158Z 10-listen-on-ipv6-by-default.sh: info: Getting the checksum of /etc/nginx/conf.d/default.conf
2024-07-28T15:41:41.613023846Z 10-listen-on-ipv6-by-default.sh: info: /etc/nginx/conf.d/default.conf differs from the packaged version
2024-07-28T15:41:41.614128103Z /docker-entrypoint.sh: Sourcing /docker-entrypoint.d/15-local-resolvers.envsh
2024-07-28T15:41:41.655591651Z /docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
2024-07-28T15:41:41.668644315Z /docker-entrypoint.sh: Launching /docker-entrypoint.d/30-tune-worker-processes.sh
2024-07-28T15:41:41.677649816Z /docker-entrypoint.sh: Configuration complete; ready for start up
2024-07-28T15:41:41.701702373Z 2024/07/28 15:41:41 [notice] 1#1: using the "epoll" event method
2024-07-28T15:41:41.701743530Z 2024/07/28 15:41:41 [notice] 1#1: nginx/1.27.0
2024-07-28T15:41:41.701753168Z 2024/07/28 15:41:41 [notice] 1#1: built by gcc 13.2.1 20231014 (Alpine 13.2.1_git20231014)
2024-07-28T15:41:41.701760772Z 2024/07/28 15:41:41 [notice] 1#1: OS: Linux 5.15.153.1-1.cm2
2024-07-28T15:41:41.701768056Z 2024/07/28 15:41:41 [notice] 1#1: getrlimit(RLIMIT_NOFILE): 131072:131072
2024-07-28T15:41:41.703971848Z 2024/07/28 15:41:41 [notice] 1#1: start worker processes
2024-07-28T15:41:41.703997947Z 2024/07/28 15:41:41 [notice] 1#1: start worker process 29
2024-07-28T15:41:41.704007184Z 2024/07/28 15:41:41 [notice] 1#1: start worker process 30
2024-07-28T15:45:34.594Z INFO - Stopping site isiworkflowwizard-dev because it failed during startup.
当我尝试访问网站网址时,出现应用程序错误。当我检查日志时,我看到 azure 说它在启动过程中失败。
当我尝试你的代码时,我遇到了同样的错误。
docker-compose.yml
将容器端口 8090 映射到主机端口 80。我在
docker-compose.yml
文件中将端口更改为80
ports:
- "80:80"
nginx.conf
以侦听端口 80 而不是 8090。nginx.conf:
server {
listen 80;
server_name localhost;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
还更新您的
docker file
以侦听端口 80。
Dockerfile:
EXPOSE 80
通过执行上述更改,我已通过 Azure 容器注册表成功将应用程序部署到 Azure 应用服务。
我运行了以下命令来构建应用程序。
docker build -t <image-name> .
运行以下命令将 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>
部署后输出: