gpt4 book ai didi

docker - 使用部署为Azure Webapp的单个Docker镜像从Python连接到Blob存储

转载 作者:行者123 更新时间:2023-12-02 20:12:19 24 4
gpt4 key购买 nike

我有一个带python的Docker,它已作为webapp部署在Azure上(我遵循了本教程:https://docs.microsoft.com/en-us/azure/app-service-web/app-service-web-tutorial-docker-python-postgresql-app)

Dockerfile看起来像这样:

FROM python:3.6.1
EXPOSE 2222 80 8080 5000
COPY daemon.json /etc/docker/
ENV http_proxy http://<LOCALPROXYADDRESS>:8080
ENV https_proxy https://<LOCALPROXYADDRESS>:8080

RUN apt-get update \
&& apt-get install -y --no-install-recommends openssh-server \
&& echo "root:Docker!" | chpasswd


COPY requirements.txt /
RUN pip install -r ./requirements.txt

COPY sshd_config /etc/ssh/


COPY init_container.sh /bin/
RUN chmod 755 /bin/init_container.sh
CMD ["/bin/init_container.sh"]

COPY app/ /app/
WORKDIR /app
ENV FLASK_APP=app.py
CMD flask run -h 0.0.0.0 -p 5000

我尝试使用azure.storage.blob中的BlockBlobService通过python连接到Blob存储。这对于在我的本地计算机上启动的容器来说效果很好。一旦将其推至 azure ,就会显示以下错误:
azure.common.AzureException: HTTPSConnectionPool(host='<CONTAINERNAME>.blob.core.windows.net', port=443):
Max retries exceeded with url: /mycontainer?restype=container
(Caused by ProxyError('Cannot connect to proxy.',
NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at
0x7fe859467cc0>: Failed to establish a new connection: [Errno -2] Name or
service not known',)))

最佳答案

尝试通过Http Proxy使用StorageClient.set_proxy方法连接到Python中的Azure Blob存储,如下面的代码。

from azure.storage.blob import BlockBlobService

block_blob_service = BlockBlobService(account_name="<your account name>", account_key="<your account key>")
super(BlockBlobService, block_blob_service).set_proxy("LOCALPROXYADDRESS", "8080")

希望能帮助到你。

关于docker - 使用部署为Azure Webapp的单个Docker镜像从Python连接到Blob存储,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46057846/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com