无法连接到位于 unix:///var/run/docker.sock 的 Docker 守护程序,位于 Azure 托管的多容器 Web 应用程序中
Cannot connect to the Docker daemon at unix:///var/run/docker.sock in Azure hosted multi-container Web App
使用 Azure Web Apps for Containers 启动 docker-compose 配置。主要代理是 Traefik,它需要访问 docker API。容器正确启动。但是traefik容器无法访问dockerAPI套接字文件
traefik容器体积的docker-compose设置为:
services:
traefik:
image: "traefik:v2.0"
[...]
volumes:
- "/var/run/docker.sock:/var/run/docker.sock:ro"
[...]
容器成功启动,日志如下:
2019-09-16 10:40:35.040 INFO - Pulling image from Docker hub:
library/traefik:v2.0 2019-09-16 10:40:35.589 INFO - v2.0 Pulling from
library/traefik 2019-09-16 10:40:35.810 INFO - Digest:
sha256:97c6da99b265de1c50e866ff66f927abb84659dcb7916c33e17623fc6969551c
2019-09-16 10:40:35.816 INFO - Status: Image is up to date for
traefik:v2.0 2019-09-16 10:40:35.835 INFO - Pull Image successful,
Time taken: 0 Minutes and 0 Seconds 2019-09-16 10:40:35.871 INFO -
Starting container for site 2019-09-16 10:40:35.872 INFO - docker run
-d -p 40317:80 --name containertest3_traefik_1_6d1c6629 -e WEBSITES_ENABLE_APP_SERVICE_STORAGE=false -e
WEBSITE_SITE_NAME=containertest3 -e WEBSITE_AUTH_ENABLED=False -e
WEBSITE_ROLE_INSTANCE_ID=0 -e
WEBSITE_HOSTNAME=containertest3.azurewebsites.net -e
WEBSITE_INSTANCE_ID=902eae0c51eb407ec9308de2a1c3fce2b35f53f6d148e328560acba2560930f0
-e HTTP_LOGGING_ENABLED=1 traefik:v2.0 --api.insecure=true --providers.docker=true --providers.docker.exposedbydefault=false --entrypoints.web.address=:80 --entryPoints.web.forwardedHeaders.insecure
2019-09-16 10:40:36.215 INFO - Pulling image from Docker hub:
containous/whoami 2019-09-16 10:40:36.779 INFO - latest Pulling from
containous/whoami 2019-09-16 10:40:36.780 INFO - Digest:
sha256:09229ae40edb92e95b15e90fef46bfadab14fd1ec2232aca717a501741fcf391
2019-09-16 10:40:36.788 INFO - Status: Image is up to date for
containous/whoami:latest 2019-09-16 10:40:36.790 INFO - Pull Image
successful, Time taken: 0 Minutes and 0 Seconds 2019-09-16
10:40:36.815 INFO - Starting container for site 2019-09-16
10:40:36.816 INFO - docker run -d -p 0:80 --name
containertest3_whoami_1_6d1c6629 -e
WEBSITES_ENABLE_APP_SERVICE_STORAGE=false -e
WEBSITE_SITE_NAME=containertest3 -e WEBSITE_AUTH_ENABLED=False -e
WEBSITE_ROLE_INSTANCE_ID=0 -e
WEBSITE_HOSTNAME=containertest3.azurewebsites.net -e
WEBSITE_INSTANCE_ID=902eae0c51eb407ec9308de2a1c3fce2b35f53f6d148e328560acba2560930f0
-e HTTP_LOGGING_ENABLED=1 containous/whoami
2019-09-16 10:40:47.048 INFO - Started multi-container app 2019-09-16
10:40:47.099 INFO - Initiating warmup request to container
containertest3_traefik_1_6d1c6629 for site containertest3 2019-09-16
10:40:47.101 INFO - Container containertest3_traefik_1_6d1c6629 for
site containertest3 initialized successfully and is ready to serve
requests.
但是,在错误日志中,Traefik 无法访问 docker api 因此无法正常工作:
2019-09-16T10:40:47.505909459Z time="2019-09-16T10:40:47Z" level=error
msg="Provider connection error Cannot connect to the Docker daemon at
unix:///var/run/docker.sock. Is the docker daemon running?, retrying
in 1.080381816s" providerName=docker
2019-09-16T10:40:48.585335458Z time="2019-09-16T10:40:48Z" level=error
msg="Failed to retrieve information of the docker client and server
host: Cannot connect to the Docker daemon at
unix:///var/run/docker.sock. Is the docker daemon running?"
Traefik 容器的最终错误:
"Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?"
知道如何在 Azure 应用程序环境中修复此错误吗?这在应用程序容器的 Azure hosting/preview 中是不可能的吗?
Azure Web App 服务不允许读取 docker.sock。
如果你想 运行 Azure 应用服务中的多容器,你需要在 traefik 中使用另一个配置提供程序。
使用 Azure Web Apps for Containers 启动 docker-compose 配置。主要代理是 Traefik,它需要访问 docker API。容器正确启动。但是traefik容器无法访问dockerAPI套接字文件
traefik容器体积的docker-compose设置为:
services:
traefik:
image: "traefik:v2.0"
[...]
volumes:
- "/var/run/docker.sock:/var/run/docker.sock:ro"
[...]
容器成功启动,日志如下:
2019-09-16 10:40:35.040 INFO - Pulling image from Docker hub: library/traefik:v2.0 2019-09-16 10:40:35.589 INFO - v2.0 Pulling from library/traefik 2019-09-16 10:40:35.810 INFO - Digest: sha256:97c6da99b265de1c50e866ff66f927abb84659dcb7916c33e17623fc6969551c 2019-09-16 10:40:35.816 INFO - Status: Image is up to date for traefik:v2.0 2019-09-16 10:40:35.835 INFO - Pull Image successful, Time taken: 0 Minutes and 0 Seconds 2019-09-16 10:40:35.871 INFO - Starting container for site 2019-09-16 10:40:35.872 INFO - docker run -d -p 40317:80 --name containertest3_traefik_1_6d1c6629 -e WEBSITES_ENABLE_APP_SERVICE_STORAGE=false -e WEBSITE_SITE_NAME=containertest3 -e WEBSITE_AUTH_ENABLED=False -e WEBSITE_ROLE_INSTANCE_ID=0 -e WEBSITE_HOSTNAME=containertest3.azurewebsites.net -e WEBSITE_INSTANCE_ID=902eae0c51eb407ec9308de2a1c3fce2b35f53f6d148e328560acba2560930f0 -e HTTP_LOGGING_ENABLED=1 traefik:v2.0 --api.insecure=true --providers.docker=true --providers.docker.exposedbydefault=false --entrypoints.web.address=:80 --entryPoints.web.forwardedHeaders.insecure
2019-09-16 10:40:36.215 INFO - Pulling image from Docker hub: containous/whoami 2019-09-16 10:40:36.779 INFO - latest Pulling from containous/whoami 2019-09-16 10:40:36.780 INFO - Digest: sha256:09229ae40edb92e95b15e90fef46bfadab14fd1ec2232aca717a501741fcf391 2019-09-16 10:40:36.788 INFO - Status: Image is up to date for containous/whoami:latest 2019-09-16 10:40:36.790 INFO - Pull Image successful, Time taken: 0 Minutes and 0 Seconds 2019-09-16 10:40:36.815 INFO - Starting container for site 2019-09-16 10:40:36.816 INFO - docker run -d -p 0:80 --name containertest3_whoami_1_6d1c6629 -e WEBSITES_ENABLE_APP_SERVICE_STORAGE=false -e WEBSITE_SITE_NAME=containertest3 -e WEBSITE_AUTH_ENABLED=False -e WEBSITE_ROLE_INSTANCE_ID=0 -e WEBSITE_HOSTNAME=containertest3.azurewebsites.net -e WEBSITE_INSTANCE_ID=902eae0c51eb407ec9308de2a1c3fce2b35f53f6d148e328560acba2560930f0 -e HTTP_LOGGING_ENABLED=1 containous/whoami
2019-09-16 10:40:47.048 INFO - Started multi-container app 2019-09-16 10:40:47.099 INFO - Initiating warmup request to container containertest3_traefik_1_6d1c6629 for site containertest3 2019-09-16 10:40:47.101 INFO - Container containertest3_traefik_1_6d1c6629 for site containertest3 initialized successfully and is ready to serve requests.
但是,在错误日志中,Traefik 无法访问 docker api 因此无法正常工作:
2019-09-16T10:40:47.505909459Z time="2019-09-16T10:40:47Z" level=error msg="Provider connection error Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?, retrying in 1.080381816s" providerName=docker
2019-09-16T10:40:48.585335458Z time="2019-09-16T10:40:48Z" level=error msg="Failed to retrieve information of the docker client and server host: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?"
Traefik 容器的最终错误: "Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?"
知道如何在 Azure 应用程序环境中修复此错误吗?这在应用程序容器的 Azure hosting/preview 中是不可能的吗?
Azure Web App 服务不允许读取 docker.sock。 如果你想 运行 Azure 应用服务中的多容器,你需要在 traefik 中使用另一个配置提供程序。