我有一个内置于 Docker 容器中的 Python Streamlit 应用程序,该应用程序在本地和 Azure 中的行为不同。
区别在于,我在本地从 docker run 获取此输出(您可以注意到我已添加到 Dockerfile 中的许多调试输出):
2024-10-22 10:53:40 USER: uid=0(root) gid=0(root) groups=0(root)
2024-10-22 10:53:40 Starting Xvfb
2024-10-22 10:53:40 Waiting for Xvfb (PID: 19) to be ready...
2024-10-22 10:53:40 Xvfb is running.
2024-10-22 10:53:40 CWD: /home/mambauser/app
2024-10-22 10:53:40 Process list: UID PID PPID C STIME TTY TIME CMD
2024-10-22 10:53:40 root 1 0 7 08:53 ? 00:00:00 /run/rosetta/rosetta /usr/bin/bash bash /usr/local/bin/docker_entrypoint.sh /opt/conda/bin/poetry run streamlit run src/similarity_demo/app.py --server.port=8501 --server.address=0.0.0.0 --server.headless=True
2024-10-22 10:53:40 root 19 1 66 08:53 ? 00:00:00 /run/rosetta/rosetta /usr/bin/Xvfb Xvfb :99 -ac -screen 0 1920x1080x24 -nolisten tcp +extension GLX +render -noreset
2024-10-22 10:53:40 root 26 1 99 08:53 ? 00:00:00 ps -ef
2024-10-22 10:53:40 USER: uid=0(root) gid=0(root) groups=0(root)
2024-10-22 10:53:40 SHELL: /bin/bash
2024-10-22 10:53:40 Files in CWD: total 520
2024-10-22 10:53:40 drwxr-xr-x 1 mambauser mambauser 4096 Oct 22 08:47 .
2024-10-22 10:53:40 drwxrwxrwx 1 mambauser mambauser 4096 Oct 22 08:48 ..
2024-10-22 10:53:40 -rw-r--r-- 1 root root 24 Oct 22 08:47 .coveragerc
2024-10-22 10:53:40 -rw-r--r-- 1 root root 534 Oct 22 08:47 .cruft.json
2024-10-22 10:53:40 -rw-r--r-- 1 root root 115 Oct 22 08:47 .dockerignore
2024-10-22 10:53:40 -rw-r--r-- 1 root root 496 Oct 22 08:47 .env.template
2024-10-22 10:53:40 -rw-r--r-- 1 root root 677 Oct 22 08:47 .env.test
2024-10-22 10:53:40 drwxr-xr-x 3 root root 4096 Oct 22 08:47 .github
2024-10-22 10:53:40 -rw-r--r-- 1 root root 1177 Oct 22 08:47 .gitignore
2024-10-22 10:53:40 -rw-r--r-- 1 root root 2020 Oct 22 08:47 .pre-commit-config.yaml
2024-10-22 10:53:40 -rw-r--r-- 1 root root 756 Oct 22 08:47 Dockerfile
2024-10-22 10:53:40 -rw-r--r-- 1 root root 1341 Oct 22 08:47 Dockerfile-streamlit
2024-10-22 10:53:40 -rw-r--r-- 1 root root 713 Oct 22 08:47 Makefile
2024-10-22 10:53:40 -rw-r--r-- 1 root root 6963 Oct 22 08:47 README.md
2024-10-22 10:53:40 drwxr-xr-x 2 root root 4096 Oct 22 08:47 code_dump
2024-10-22 10:53:40 -rw-r--r-- 1 root root 202 Oct 22 08:47 docker-compose-streamlit.yml
2024-10-22 10:53:40 -rw-r--r-- 1 root root 1556 Oct 22 08:47 docker_entrypoint.sh
2024-10-22 10:53:40 drwxr-xr-x 3 root root 4096 Oct 22 08:47 docs
2024-10-22 10:53:40 -rw-r--r-- 1 root root 112 Oct 22 08:47 environment.yml
2024-10-22 10:53:40 drwxr-xr-x 2 root root 4096 Oct 22 08:47 notebooks
2024-10-22 10:53:40 -rw-r--r-- 1 root root 423394 Oct 22 08:47 poetry.lock
2024-10-22 10:53:40 -rw-r--r-- 1 root root 2724 Oct 22 08:47 pyproject.toml
2024-10-22 10:53:40 drwxr-xr-x 4 root root 4096 Oct 22 08:47 src
2024-10-22 10:53:40 drwxr-xr-x 7 root root 4096 Oct 22 08:47 testdata
2024-10-22 10:53:40 drwxr-xr-x 4 root root 4096 Oct 22 08:47 tests
2024-10-22 10:53:40 -rw-r--r-- 1 root root 1642 Oct 22 08:47 tox.ini
2024-10-22 10:53:40 Starting Streamlit ...
2024-10-22 10:53:40 ... using command: /opt/conda/bin/poetry run streamlit run src/similarity_demo/app.py --server.port=8501 --server.address=0.0.0.0 --server.headless=True
2024-10-22 10:53:41
2024-10-22 10:53:41 Collecting usage statistics. To deactivate, set browser.gatherUsageStats to false.
2024-10-22 10:53:41
2024-10-22 10:53:42
2024-10-22 10:53:42 You can now view your Streamlit app in your browser.
2024-10-22 10:53:42
2024-10-22 10:53:42 URL: http://0.0.0.0:8501
2024-10-22 10:53:42
2024-10-22 10:53:41 Skipping virtualenv creation, as specified in config file.
2024-10-22T09:15:05.583Z INFO - 53a70d9203fb Extracting 78MB / 81MB
2024-10-22T09:15:05.690Z INFO - 53a70d9203fb Extracting 79MB / 81MB
2024-10-22T09:15:06.027Z INFO - 53a70d9203fb Extracting 81MB / 81MB
2024-10-22T09:15:06.105Z INFO - 53a70d9203fb Pull complete
2024-10-22T09:15:06.106Z INFO - 1b9886ab8f6a Extracting 1KB / 1KB
2024-10-22T09:15:06.117Z INFO - 1b9886ab8f6a Extracting 1KB / 1KB
2024-10-22T09:15:06.266Z INFO - 1b9886ab8f6a Pull complete
2024-10-22T09:15:06.270Z INFO - a9787636e47e Extracting 1KB / 1KB
2024-10-22T09:15:06.276Z INFO - a9787636e47e Extracting 1KB / 1KB
2024-10-22T09:15:06.400Z INFO - a9787636e47e Pull complete
2024-10-22T09:15:06.425Z INFO - Digest: sha256:7e05fd9db626dd9fd428db3977d3f3d57ad4c91e0fd23f0a51b858d4f0e879b0
2024-10-22T09:15:06.428Z INFO - Status: Downloaded newer image for private.azurecr.io/mine/mine-demo-similarity:2024-10-22T08-47
2024-10-22T09:15:06.450Z INFO - Pull Image successful, Time taken: 217 Seconds
2024-10-22T09:15:06.635Z INFO - Starting container for site
2024-10-22T09:15:06.636Z INFO - docker run -d -p 4697:8501 --name random-docker-app_0_6f2c7841 -e WEBSITE_USE_DIAGNOSTIC_SERVER=false -e WEBSITES_PORT=8501 -e WEBSITE_SITE_NAME=random-docker-app -e WEBSITE_AUTH_ENABLED=False -e WEBSITE_ROLE_INSTANCE_ID=0 -e WEBSITE_HOSTNAME=random-docker-app.azurewebsites.net -e WEBSITE_INSTANCE_ID=dd5333bc46ebdef0807c9a794715b81ab60911ab0399bb12ba901cb4f42406b2 -e HTTP_LOGGING_ENABLED=1 private.azurecr.io/mine/mine-demo-similarity:2024-10-22T08-47
2024-10-22T09:15:09.492Z INFO - Initiating warmup request to container random-docker-app_0_6f2c7841_msiProxy for site random-docker-app
2024-10-22T09:15:09.679Z INFO - Container random-docker-app_0_6f2c7841_msiProxy for site random-docker-app initialized successfully and is ready to serve requests.
2024-10-22T09:15:09.680Z INFO - Initiating warmup request to container random-docker-app_0_6f2c7841 for site random-docker-app
2024-10-22T09:15:08.923024295Z USER: uid=0(root) gid=0(root) groups=0(root)
2024-10-22T09:15:09.169333591Z Starting Xvfb
2024-10-22T09:15:09.169796296Z Waiting for Xvfb (PID: 18) to be ready...
2024-10-22T09:15:09.709325927Z Xvfb is running.
2024-10-22T09:15:09.710587739Z CWD: /home/mambauser/app
2024-10-22T09:15:09.742441436Z Process list: UID PID PPID C STIME TTY TIME CMD
2024-10-22T09:15:09.742474336Z root 1 0 6 09:15 ? 00:00:00 bash /usr/local/bin/docker_entrypoint.sh /opt/conda/bin/poetry run streamlit run src/similarity_demo/app.py --server.port=8501 --server.address=0.0.0.0 --server.headless=True
2024-10-22T09:15:09.742484836Z root 18 1 25 09:15 ? 00:00:00 Xvfb :99 -ac -screen 0 1920x1080x24 -nolisten tcp +extension GLX +render -noreset
2024-10-22T09:15:09.742489036Z root 20 0 23 09:15 ? 00:00:00 /appservice/dotnet/dotnet kuduagent.dll
2024-10-22T09:15:09.742493036Z root 38 1 50 09:15 ? 00:00:00 ps -ef
2024-10-22T09:15:09.746524474Z USER: uid=0(root) gid=0(root) groups=0(root)
2024-10-22T09:15:09.746547174Z SHELL: /bin/bash
2024-10-22T09:15:09.776348652Z Files in CWD: total 0
2024-10-22T09:15:09.776385652Z drwxrwxrwx 2 nobody nogroup 0 Oct 10 09:10 .
2024-10-22T09:15:09.776576554Z drwxrwxrwx 2 nobody nogroup 0 Oct 10 09:10 ..
2024-10-22T09:15:09.778375571Z Starting Streamlit ...
2024-10-22T09:15:09.778639573Z ... using command: /opt/conda/bin/poetry run streamlit run src/similarity_demo/app.py --server.port=8501 --server.address=0.0.0.0 --server.headless=True
2024-10-22T09:15:12.297968367Z
2024-10-22T09:15:12.298010568Z Poetry could not find a pyproject.toml file in /home/mambauser/app or its parents
2024-10-22T09:15:12.889Z ERROR - Container random-docker-app_0_6f2c7841 for site random-docker-app has exited, failing site start
2024-10-22T09:15:12.897Z ERROR - Container random-docker-app_0_6f2c7841 didn't respond to HTTP pings on port: 8501, failing site start. See container logs for debugging.
2024-10-22T09:15:13.594Z INFO - Stopping site random-docker-app because it failed during startup.
我找不到任何原因为什么同一个容器映像在 Azure 中看起来没有文件,但在多个本地主机上包含文件。
其他相关文件有:
FROM mambaorg/micromamba:1.5.8 AS builder
COPY --chown=$MAMBA_USER:$MAMBA_USER ./environment.yml /tmp/environment.yml
RUN micromamba install -y -n base -f /tmp/environment.yml && \
micromamba clean --all --yes
ENV POETRY_NO_INTERACTION=1 \
POETRY_VIRTUALENVS_CREATE=0 \
POETRY_VIRTUALENVS_OPTIONS_ALWAYS_COPY=1
RUN mkdir /home/mambauser/app
COPY --chown=$MAMBA_USER:$MAMBA_USER poetry.lock pyproject.toml /home/mambauser/app/
WORKDIR /home/mambauser/app
ARG MAMBA_DOCKERFILE_ACTIVATE=1
RUN poetry install --only main --no-root
COPY . /home/mambauser/app
RUN poetry install --only main
USER root
WORKDIR /home/mambauser/app
RUN apt-get update && apt-get install -y --no-install-recommends \
make \
procps \
libgl1-mesa-dev \
mesa-utils \
xvfb \
x11-utils \
&& rm -rf /var/lib/apt/lists/*
COPY docker_entrypoint.sh /usr/local/bin/docker_entrypoint.sh
RUN chmod +x /usr/local/bin/docker_entrypoint.sh
#USER $MAMBA_USER
# get current GIT_SHA from environment into build variable
ARG GIT_SHA
# put build variable into docker image environment variable
ENV GIT_SHA=${GIT_SHA}
EXPOSE 8501
ENTRYPOINT ["/usr/local/bin/docker_entrypoint.sh", "/opt/conda/bin/poetry", "run", "streamlit", "run", "src/similarity_demo/app.py", "--server.port=8501", "--server.address=0.0.0.0", "--server.headless=True"]
#!/usr/bin/env bash
set -ef -o pipefail
# If the file /etc/arg_mamba_user exists and its contents don't match $MAMBA_USER...
if [[ -f /etc/arg_mamba_user && "${MAMBA_USER}" != "$(cat "/etc/arg_mamba_user")" ]]; then
echo "ERROR: This micromamba-docker image was built with" \
"'ARG MAMBA_USER=$(cat "/etc/arg_mamba_user")', but the corresponding" \
"environment variable has been modified to 'MAMBA_USER=${MAMBA_USER}'." \
"For instructions on how to properly change the username, please refer" \
"to the documentation at <https://github.com/mamba-org/micromamba-docker>." >&2
exit 1
fi
echo "USER: $(id)"
# if USER is not set and not root
if [[ ! -v USER && $(id -u) -gt 0 ]]; then
# should get here if 'docker run...' was passed -u with a numeric UID
export USER="$MAMBA_USER"
export HOME="/home/$USER"
fi
source _activate_current_env.sh
export DISPLAY=:99
# Start Xvfb
echo "Starting Xvfb"
Xvfb :99 -ac -screen 0 1920x1080x24 -nolisten tcp +extension GLX +render -noreset &
Xvfb_pid="$!"
echo "Waiting for Xvfb (PID: $Xvfb_pid) to be ready..."
while ! xdpyinfo -display "${DISPLAY}" > /dev/null 2>&1; do
sleep 0.1
done
echo "Xvfb is running."
echo "CWD: $(pwd)"
echo "Process list: $(ps -ef)"
echo "USER: $(id)"
echo "SHELL: $SHELL"
echo "Files in CWD: $(ls -la)"
echo "Starting Streamlit ..."
echo "... using command: $@"
exec "$@"
trap "echo 'Stopping'; kill -SIGTERM $Xvfb_pid" SIGINT SIGTERM
# Wait for process to end.
kill $Xvfb_pid
echo "Waiting for Xvfb (PID: $Xvfb_pid) to shut down..."
wait $Xvfb_pid
services:
app:
image: redacted.azurecr.io/mine/mine-demo-similarity:2024-10-22T08-47
platform: linux/amd64
env_file:
- .env_azure
ports:
- 8501:8501
{
"id": "/subscriptions/redacted_subs/resourceGroups/redacted_rg/providers/Microsoft.Web/sites/redacted_app",
"name": "redacted_app",
"type": "Microsoft.Web/sites",
"kind": "app,linux,container",
"location": "West Europe",
"tags": {
"environment": "demo"
},
"properties": {
"name": "redacted_app",
"state": "Running",
"hostNames": [
"redacted_app.azurewebsites.net"
],
"webSpace": "redacted_rg-WestEuropewebspace-Linux",
"selfLink": "https://waws-prod-am4-111.api.azurewebsites.windows.net:454/subscriptions/redacted_subs/webspaces/redacted_rg-WestEuropewebspace-Linux/sites/redacted_app",
"repositorySiteName": "redacted_app",
"owner": null,
"usageState": 0,
"enabled": true,
"adminEnabled": true,
"siteScopedCertificatesEnabled": false,
"afdEnabled": false,
"enabledHostNames": [
"redacted_app.azurewebsites.net",
"redacted_app.scm.azurewebsites.net"
],
"siteProperties": {
"metadata": null,
"properties": [
{
"name": "LinuxFxVersion",
"value": "DOCKER|redacted_acr.azurecr.io/mine/mine-demo-similarity:2024-10-22T08-47"
},
{
"name": "WindowsFxVersion",
"value": null
}
],
"appSettings": null
},
"availabilityState": 0,
"sslCertificates": null,
"csrs": [],
"cers": null,
"siteMode": null,
"hostNameSslStates": [
{
"name": "redacted_app.azurewebsites.net",
"sslState": 0,
"ipBasedSslResult": null,
"virtualIP": null,
"virtualIPv6": null,
"thumbprint": null,
"certificateResourceId": null,
"toUpdate": null,
"toUpdateIpBasedSsl": null,
"ipBasedSslState": 0,
"hostType": 0
},
{
"name": "redacted_app.scm.azurewebsites.net",
"sslState": 0,
"ipBasedSslResult": null,
"virtualIP": null,
"virtualIPv6": null,
"thumbprint": null,
"certificateResourceId": null,
"toUpdate": null,
"toUpdateIpBasedSsl": null,
"ipBasedSslState": 0,
"hostType": 1
}
],
"computeMode": null,
"serverFarm": null,
"serverFarmId": "/subscriptions/redacted_subs/resourceGroups/redacted_rg/providers/Microsoft.Web/serverfarms/redacted_app-plan",
"reserved": true,
"isXenon": false,
"hyperV": false,
"lastModifiedTimeUtc": "2024-10-22T09:05:15.3766667",
"storageRecoveryDefaultState": "Running",
"contentAvailabilityState": 0,
"runtimeAvailabilityState": 0,
"dnsConfiguration": {},
"vnetRouteAllEnabled": false,
"containerAllocationSubnet": null,
"useContainerLocalhostBindings": null,
"vnetImagePullEnabled": false,
"vnetContentShareEnabled": false,
"outboundVnetRouting": null,
"siteConfig": {
"numberOfWorkers": 1,
"defaultDocuments": null,
"netFrameworkVersion": null,
"phpVersion": null,
"pythonVersion": null,
"nodeVersion": null,
"powerShellVersion": null,
"linuxFxVersion": "DOCKER|redacted_acr.azurecr.io/mine/mine-demo-similarity:2024-10-22T08-47",
"windowsFxVersion": null,
"windowsConfiguredStacks": null,
"requestTracingEnabled": null,
"remoteDebuggingEnabled": null,
"remoteDebuggingVersion": null,
"httpLoggingEnabled": null,
"azureMonitorLogCategories": null,
"acrUseManagedIdentityCreds": false,
"acrUserManagedIdentityID": null,
"logsDirectorySizeLimit": null,
"detailedErrorLoggingEnabled": null,
"publishingUsername": null,
"publishingPassword": null,
"appSettings": null,
"metadata": null,
"connectionStrings": null,
"machineKey": null,
"handlerMappings": null,
"documentRoot": null,
"scmType": null,
"use32BitWorkerProcess": null,
"webSocketsEnabled": null,
"alwaysOn": true,
"javaVersion": null,
"javaContainer": null,
"javaContainerVersion": null,
"appCommandLine": null,
"managedPipelineMode": null,
"virtualApplications": null,
"winAuthAdminState": null,
"winAuthTenantState": null,
"customAppPoolIdentityAdminState": null,
"customAppPoolIdentityTenantState": null,
"runtimeADUser": null,
"runtimeADUserPassword": null,
"loadBalancing": null,
"routingRules": null,
"experiments": null,
"limits": null,
"autoHealEnabled": null,
"autoHealRules": null,
"tracingOptions": null,
"vnetName": null,
"vnetRouteAllEnabled": null,
"vnetPrivatePortsCount": null,
"publicNetworkAccess": null,
"cors": null,
"push": null,
"apiDefinition": null,
"apiManagementConfig": null,
"autoSwapSlotName": null,
"localMySqlEnabled": null,
"managedServiceIdentityId": null,
"xManagedServiceIdentityId": null,
"keyVaultReferenceIdentity": null,
"ipSecurityRestrictions": null,
"ipSecurityRestrictionsDefaultAction": null,
"scmIpSecurityRestrictions": null,
"scmIpSecurityRestrictionsDefaultAction": null,
"scmIpSecurityRestrictionsUseMain": null,
"http20Enabled": false,
"minTlsVersion": null,
"minTlsCipherSuite": null,
"scmMinTlsCipherSuite": null,
"supportedTlsCipherSuites": null,
"scmSupportedTlsCipherSuites": null,
"scmMinTlsVersion": null,
"ftpsState": null,
"preWarmedInstanceCount": null,
"functionAppScaleLimit": 0,
"elasticWebAppScaleLimit": null,
"healthCheckPath": null,
"fileChangeAuditEnabled": null,
"functionsRuntimeScaleMonitoringEnabled": null,
"websiteTimeZone": null,
"minimumElasticInstanceCount": 1,
"azureStorageAccounts": null,
"http20ProxyFlag": null,
"sitePort": null,
"antivirusScanEnabled": null,
"storageType": null,
"sitePrivateLinkHostEnabled": null,
"clusteringEnabled": false
},
"functionAppConfig": null,
"daprConfig": null,
"deploymentId": "redacted_app",
"slotName": null,
"trafficManagerHostNames": null,
"sku": "Basic",
"scmSiteAlsoStopped": false,
"targetSwapSlot": null,
"hostingEnvironment": null,
"hostingEnvironmentProfile": null,
"clientAffinityEnabled": false,
"clientAffinityProxyEnabled": false,
"blockPathTraversal": false,
"clientCertEnabled": false,
"clientCertMode": 0,
"clientCertExclusionPaths": null,
"hostNamesDisabled": false,
"ipMode": "IPv4",
"vnetBackupRestoreEnabled": false,
"domainVerificationIdentifiers": null,
"customDomainVerificationId": "47ECAC6ABFD9B4AAAAAAAAAAAAAAAAAAAAAAAAD726A05EB70166F3CCEF",
"kind": "app,linux,container",
"managedEnvironmentId": null,
"workloadProfileName": null,
"resourceConfig": null,
"inboundIpAddress": "13.69.68.64",
"possibleInboundIpAddresses": "13.69.68.64",
"ftpUsername": "redacted_app\\$redacted_app",
"ftpsHostName": "ftps://waws-prod-am4-111.ftp.azurewebsites.windows.net/site/wwwroot",
"outboundIpAddresses": "redacted",
"possibleOutboundIpAddresses": "redacted",
"containerSize": 0,
"dailyMemoryTimeQuota": 0,
"suspendedTill": null,
"siteDisabledReason": 0,
"functionExecutionUnitsCache": null,
"maxNumberOfWorkers": null,
"homeStamp": "waws-prod-am4-111",
"cloningInfo": null,
"hostingEnvironmentId": null,
"tags": {
"environment": "demo"
},
"resourceGroup": "redacted_rg",
"defaultHostName": "redacted_app.azurewebsites.net",
"slotSwapStatus": null,
"httpsOnly": false,
"endToEndEncryptionEnabled": false,
"functionsRuntimeAdminIsolationEnabled": false,
"redundancyMode": 0,
"inProgressOperationId": null,
"geoDistributions": null,
"privateEndpointConnections": [],
"publicNetworkAccess": "Enabled",
"buildVersion": null,
"targetBuildVersion": null,
"migrationState": null,
"eligibleLogCategories": "AppServiceAppLogs,AppServiceAuditLogs,AppServiceConsoleLogs,AppServiceHTTPLogs,AppServiceIPSecAuditLogs,AppServicePlatformLogs,ScanLogs,AppServiceAuthenticationLogs",
"inFlightFeatures": [
"SiteContainers"
],
"storageAccountRequired": false,
"virtualNetworkSubnetId": null,
"keyVaultReferenceIdentity": "SystemAssigned",
"autoGeneratedDomainNameLabelScope": null,
"defaultHostNameScope": 0,
"privateLinkIdentifiers": null,
"sshEnabled": null
},
"identity": {
"type": "SystemAssigned",
"tenantId": "redacted_tenant",
"principalId": "redacted_principal"
}
}
这是线索:
2024-10-22T09:15:12.889Z ERROR - Container random-docker-app_0_6f2c7841 for site random-docker-app has exited, failing site start
2024-10-22T09:15:12.897Z ERROR - Container random-docker-app_0_6f2c7841 didn't respond to HTTP pings on port: 8501, failing site start. See container logs for debugging.
默认情况下,应用服务假定您的自定义容器正在侦听端口 80。如果您的容器侦听其他端口,请在应用服务应用中设置 WEBSITES_PORT 应用设置。您可以通过 Cloud Shell 进行设置。在重击中:
az webapp config appsettings set --resource-group <group-name> --name <app-name> --settings WEBSITES_PORT=8000
(来源)