minio / mc

Unix like utilities for object store
https://min.io/download
GNU Affero General Public License v3.0
2.86k stars 548 forks source link

mc: <ERROR> Unable to initialize new alias from the provided credentials. #4992

Closed T4mmi closed 3 months ago

T4mmi commented 3 months ago

Hi all, I'm trying to create a bucket inside a docker-compose service ... but I cannot manage to make it work !

$ docker-compose up mkdir
Recreating minio-server ... done
Recreating minio-client ... done
Attaching to minio-client
minio-client | URL: http://localhost:9000
minio-client | Credentials: minio:minioadmin
minio-client | mc: <ERROR> Unable to initialize new alias from the provided credentials. 
Get "http://localhost:9000/probe-bsign-09onhadk2p6hpr1e3vd6ki3npmzzrg/?location=": dial tcp 127.0.0.1:9000: connect: connection refused.
minio-client exited with code 1

Everything works if I do it "by hand", i.e.:

Steps to reproduce the behavior

docker-compose.yml

services:

  # run an S3 instance (minio)
  s3:
    image: minio/minio
    container_name: minio-server
    extra_hosts:
      - "host.docker.internal:host-gateway"
    ports:
      - ${S3_API_PORT}:${S3_API_PORT}
      - ${S3_WEB_PORT}:${S3_WEB_PORT}
    volumes:
      - .minio/data:/data
      - .minio/config:/root/.minio/
    env_file: .env
    environment:
      MINIO_ROOT_USER: ${S3_ACCESS_KEY}
      MINIO_ROOT_PASSWORD: ${S3_SECRET_KEY}
      MINIO_SERVER_URL: ${S3_ENDPOINT_URL}
      MINIO_BROWSER_REDIRECT_URL: ${S3_WEB_URL}
    command: server /data --address ":${S3_API_PORT}" --console-address ":${S3_WEB_PORT}"
    healthcheck:
      test: ["CMD", "mc", "ready", "local"]
      interval: 5s
      timeout: 5s
      retries: 5
    restart: always

  # create the bucket
  mkdir:
    image: minio/mc
    container_name: minio-client
    env_file: .env
    depends_on:
      s3:
        condition: service_healthy
    extra_hosts:
      - "host.docker.internal:host-gateway"
    entrypoint: >
      /bin/sh -c "
      echo URL: ${S3_ENDPOINT_URL};
      echo Credentials: ${S3_ACCESS_KEY}:${S3_SECRET_KEY};
      /usr/bin/mc alias set s3 ${S3_ENDPOINT_URL} ${S3_ACCESS_KEY} ${S3_SECRET_KEY} &&
      /usr/bin/mc mb s3/${S3_BUCKET_NAME} --ignore-existing &&
      /usr/bin/mc anonymous set public s3/${S3_BUCKET_NAME}
      "

.env

S3_API_PORT="9000"
S3_WEB_PORT="9001"
S3_ACCESS_KEY="minio"
S3_SECRET_KEY="minioadmin"
S3_WEB_URL="http://localhost:${S3_WEB_PORT}"
S3_ENDPOINT_URL="http://localhost:${S3_API_PORT}"
S3_BUCKET_NAME="bucket"

System information

WSL-Ubuntu 5.15.153.1-microsoft-standard-WSL2 Docker version 24.0.7, build 24.0.7-0ubuntu2~22.04.1 docker-compose version 1.29.2

T4mmi commented 3 months ago

the https://github.com/minio/mc/issues/3599 resolution doesn't work here since the healthcheck/depends_on:service_healthy ensures that the instance is up&ready, AND i can do the creation manually.

It seems to me that the minio-client container cannot communicate with the minio-server one ... but I cannot find why

T4mmi commented 3 months ago

Ok, the problem came from the localhost mapping that wasn't consistent between the containers ... I missunderstood the extra_hosts ...

    extra_hosts:
      - "host.docker.internal:host-gateway"

is removed and replaced by

network_mode: service:s3

full docker-compose.yml looks like:

services:

  # run an S3 instance (minio)
  s3:
    image: minio/minio
    container_name: minio-server
    ports:
      - ${S3_API_PORT}:${S3_API_PORT}
      - ${S3_WEB_PORT}:${S3_WEB_PORT}
    volumes:
      - .minio/data:/data
      - .minio/config:/root/.minio/
    env_file: .env
    environment:
      MINIO_ROOT_USER: ${S3_ACCESS_KEY}
      MINIO_ROOT_PASSWORD: ${S3_SECRET_KEY}
      MINIO_SERVER_URL: ${S3_ENDPOINT_URL}
      MINIO_BROWSER_REDIRECT_URL: ${S3_WEB_URL}
    command: server /data --address ":${S3_API_PORT}" --console-address ":${S3_WEB_PORT}"
    healthcheck:
      test: ["CMD", "mc", "ready", "local"]
      interval: 5s
      timeout: 1s
    restart: always

  # create the bucket
  mkdir:
    image: minio/mc
    container_name: minio-client
    env_file: .env
    depends_on:
      s3:
        condition: service_healthy
    network_mode: service:s3
    entrypoint: >
      /bin/sh -c "
      echo URL: ${S3_ENDPOINT_URL};
      echo Credentials: ${S3_ACCESS_KEY}:${S3_SECRET_KEY};
      /usr/bin/mc alias set s3 ${S3_ENDPOINT_URL} ${S3_ACCESS_KEY} ${S3_SECRET_KEY};
      /usr/bin/mc mb s3/${S3_BUCKET_NAME} --ignore-existing;
      /usr/bin/mc anonymous set public s3/${S3_BUCKET_NAME}
      "
marktheunissen commented 3 months ago

It sounds like your issue is resolved, closing.