1

I am setting up a local Azure Blob Storage using Docker container & Docker-compose. However, when I start creating blob containers and uploading files it throws me the error as below.

azure.common.AzureException: HTTPConnectionPool(host='127.0.0.1', port=10000): Max retries exceeded with url: /devstoreaccount1/quickstartblobs?restype=container (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f1068d0f748>: Failed to establish a new connection: [Errno 111] Connection refused',))

Here is my docker-compose:

version: "3.9"
   
services:
 
      
  db:
    image: postgres
    volumes:
      - ./data/db:/var/lib/postgresql/data
    environment:
      - POSTGRES_DB=postgres
      - POSTGRES_USER=postgres
      - POSTGRES_PASSWORD=postgres
      - DEBUG=FALSE
      - AZURE_STORAGE_CONNECTION_STRING=DefaultEndpointsProtocol=https;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;BlobEndpoint=https://127.0.0.1:10000/devstoreaccount1;
  web:
    build: .
    command: python manage.py runserver 0.0.0.0:8000
    volumes:
      - .:/code
    ports:
      - 8000:8000
      - 5678:5678
    depends_on:
      - db
      
  azurite:
    image: mcr.microsoft.com/azure-storage/azurite
    ports:
      - "127.0.0.1:10000:10000"

Requirements.txt

djangorestframework==3.11.2
Django==3.1.8
Pygments==2.7.4
Markdown==3.2.1
coreapi==2.3.3
psycopg2-binary==2.8.4
dj-database-url==0.5.0
gunicorn==20.0.4
whitenoise==5.0.1
PyYAML==5.4
azure-storage-blob==2.1.0
ptvsd==4.3.2
azure-common==1.1.23
azure-storage-common==2.1.0
requests==2.25.1
six==1.11.0
urllib3==1.26.3

Code:

 blob_service_client = BlockBlobService(
            account_name='devstoreaccount1', account_key='Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==',is_emulated=True)

        # Create a container called 'quickstartblobs'.
        container_name = 'quickstartblobs'
        blob_service_client.create_container(container_name)
Mostafa Ghadimi
  • 5,883
  • 8
  • 64
  • 102
David
  • 607
  • 1
  • 6
  • 19

1 Answers1

0

You can remove the ports section for azurite service in your compose file and in your application provide the connection string and specify the blob endpoint (as mentioned here: https://learn.microsoft.com/en-us/azure/storage/common/storage-use-azurite#connection-strings) as BlobEndpoint=http://azurite:10000

When you use docker local bridge (created for services where deployed using compose), container name if provided explicitly else the service name can be used to access the service.

akazuko
  • 1,394
  • 11
  • 19
  • Thank you for your answer. It works like a champ, however, I changed the SDK to the latest version 12.8.1 instead of BlobStorageService; I use BloblStorageClient. Do you have any advice about the SDK? Should I use the old or new's? – David Jul 04 '21 at 01:50
  • I guess newer client will have bug and improvement fixes which should help. You can also refer to the change log between the versions to see if the changes help your usecase/ application. – akazuko Jul 04 '21 at 15:18