5

I am running a minio-server in the container of docker-compose. I am trying to upload a file to the minio-server in the container, from the host machine (Ubuntu) (instead of container) by using minio-client (python SDK). I did not make it happen as expected. I am not clear if it is because of my endpoint(URL), or due to the connection issue between container and host?

The endpoints i tried:

url_1 = 'http://minio:9000' # from my default setup for minio link;

url_2 = 'http://localhost:9000/minio/test' # from Minio browser.

For url_1, what i got is: " botocore.exceptions.EndpointConnectionError: Could not connect to the endpoint URL: http://minio:9000/test ". The line of error: s3.create_bucket(Bucket='test')

For url_2, what i got is: " All access to this bucket has been disabled. ". The line of error: s3.create_bucket(Bucket='test')

I tried the similar thing: activating my minio-server and minio-client both in my host machine. Then i upload file from the minio-client to the minio-server. I can see those uploaded files in Minio browser in localhost.

######### python script uploading files
import boto3

from botocore.client import Config

import os

import getpass

my_url1='http://minio:9000' # this is from os.environ['S3_URL']
my_url2='http://localhost:9000/minio/test' # this is from browser

s3 = boto3.resource('s3',
                endpoint_url=my_url2,
                aws_access_key_id=os.environ['USER'],
                aws_secret_access_key = getpass.getpass('Password:'),
                config = Config(signature_version='s3v4'),
                region_name='us-east-1')

print ('********', s3)

s3.create_bucket(Bucket='test')

uploadfile= os.getcwd()+'/'+'test.txt'
s3.Bucket('testBucket').upload_file(uploadfile,'txt')
######### docker-yml file for Minio
minio:
   image: minio/minio
   entrypoint:
      - minio
      - server
      -/data
   ports:
      - "9000:9000"
   environment:
      minio_access_key = username
      minio_secret_key = password

mc:
   image: minio/mc
   environment: 
      minio_access_key = username
      minio_secret_key = password
   entrypoint:
      /bin/sh -c     
   depends_on:
      minio

i expected to see the uploaded files from the minio browser('http://localhost:9000/minio/test') , just like what i did from activating minio-server and minio-client both at the host.

3 Answers 3

4

With default docker networking, you would have to try to access minio at http://localhost:9000 on your host. So you can just use this URL in your Python script. The http://minio:9000 will work from containers on the same docker network as your minio server.

Sign up to request clarification or add additional context in comments.

Comments

0

Try to use Pyminio client instead of boto3.

import os
from pyminio import Pyminio

pyminio_client = Pyminio.from_credentials(
    endpoint='http://localhost:9000/',
    access_key=os.environ['USER'],
    secret_key=getpass.getpass('Password:')
)

pyminio_client.mkdirs('/test/')

pyminio_client.put_file(
    to_path='/test/',
    file_path=os.path.join(os.getcwd(), 'test.txt')
)

Comments

0

use this configuration in your compose.yml file

version: "3"
services:
    
    minio:
        image: "minio/minio"
        container_name: mi
        ports:
            - "9000:9000"
        environment:
            - "MINIO_ACCESS_KEY=ACCRESS"
            - "MINIO_SECRET_KEY=SECRET"
        restart: always
        command: server /data
    mc:
        image: minio/mc
        container_name: mc
        network_mode: host
        entrypoint: >
          /bin/sh -c "
          /usr/bin/mc config host add minio http://127.0.0.1:9000 ACCESS SECRET;
          /usr/bin/mc rm -r --force minio/psb-new;
          /usr/bin/mc mb minio/psb-new;
          /usr/bin/mc policy set public minio/psb-new;
          exit 0;
          "
networks:
  elastic:
    driver: bridge

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.