简体   繁体   中英

Connection Refused to Minio Docker instance from my Django Application

Hi im trying to connect to my Minio instance which is running inside a docker container from a django instance, which is also running inside a docker container.

I keep getting this error:

2020-10-29 13:59:17,568 urllib3.util.retry DEBUG    Incremented Retry for (url='/'): Retry(total=0, connect=None, read=None, redirect=None, status=None)
2020-10-29 13:59:20,773 urllib3.connectionpool WARNING  Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLError(1, '[SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1076)'))': /
2020-10-29 13:59:20,774 urllib3.connectionpool DEBUG    Starting new HTTPS connection (6): minio:9000

My docker-compose file is the following:

version: "3.7"

services:
    db:
        container_name: db
        image: mariadb
        restart: always
        ports:
          - '3306:3306'
        environment:
          MYSQL_DATABASE: 'django_dev'
          MYSQL_USER: 'user'
          MYSQL_PASSWORD: 'password'
          MYSQL_ROOT_PASSWORD: 'password'
        volumes:
          - ./mariadb:/var/lib/mysql

    minio:
        container_name: minio
        image: minio/minio
        command: 'server /export'
        environment: 
          MINIO_ACCESS_KEY: weak_access_key
          MINIO_SECRET_KEY: weak_secret_key
        ports:
          - '9000:9000'
        volumes:
          - ./minio:/export

    web:
        container_name: web
        build: 
          context: ./django/
          dockerfile: ./Dockerfile
          target: dev
        command: python manage.py runserver 0.0.0.0:8000
        volumes: 
          - ./django:/usr/src/app
        ports:
          - "8000:8000"
        env_file: 
          - ./.env.dev
        depends_on:
          - minio
          - db

    phpmyadmin:
        container_name: db_viewer
        image: phpmyadmin/phpmyadmin
        restart: always
        ports:
          - '8080:80'
        environment:
          PMA_HOST: db
          MYSQL_ROOT_PASSWORD: 'password'
        depends_on:
          - db

The code to set up the client:

minioClient = Minio('minio:9000',
                  access_key='weak_access_key',
                  secret_key='weak_secret_key')
minioClient.list_buckets()

Im using WSL2 as development environment.

Python Version 3.7.7, Django Version 3.1.2, Minio Version 6.0.0

Thank you for your time.

*Edit: I reach the minio service with localhost:9000 from my machine.

If you're working on localhost, it won't use https . Minio constructor's default implementation assumes that the connection is https . To use http instead of https ,pass secure=False to Minio constructor.

minioClient = Minio('minio:9000',
                  access_key='weak_access_key',
                  secret_key='weak_secret_key',
                  secure=False)
minioClient.list_buckets()

By Default, the django minio connector tries to connect to minio using https. As you're not running minio with https, the connector errors out, cause it doesn't understand the protocol. To fix, just set MINIO_STORAGE_USE_HTTPS=False (See here for the official docs) in djangos settings.py.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM