Benedikt Schmidt
Benedikt Schmidt

Reputation: 11

Connect to Blob Storage from Python using Individual Docker Image Deployed as Azure Webapp

I have a Docker with python which is deployed as webapp on Azure (I followed this tutorial: https://learn.microsoft.com/en-us/azure/app-service-web/app-service-web-tutorial-docker-python-postgresql-app)

The Dockerfile looks like this:

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

I try to connect via python to a Blob Storage using BlockBlobService from azure.storage.blob. This works fine for a container started on my local machine. Once I push it to azure, the following error is printed:

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',)))

Upvotes: 1

Views: 1642

Answers (1)

Peter Pan
Peter Pan

Reputation: 24148

Try to connect to Azure Blob Storage in Python with StorageClient.set_proxy method via Http Proxy, like the code below.

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")

Hope it helps.

Upvotes: 0

Related Questions