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

时间:2017-09-05 14:47:46

标签: docker azure-storage-blobs azure-web-app-service

我有一个带有python的Docker,它在Azure上部署为webapp(我遵循了本教程: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',)))

1 个答案:

答案 0 :(得分:0)

尝试使用StorageClient.set_proxy方法通过Http 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")

希望它有所帮助。