代码之家  ›  专栏  ›  技术社区  ›  Vitaly Igorevich

无法通过carrierwave fog aws将文件上载到minio(docker compose)

  •  0
  • Vitaly Igorevich  · 技术社区  · 7 年前

    尝试通过carrierwave将文件上载到minio时出现错误Excon::错误::Socket(getaddrinfo:名称或服务未知(SocketError))。

    version: '3'
    services:
      minio:
        image: minio/minio
        deploy:
          resources:
            limits:
              memory: 256m
        volumes:
          - 'minio:/var/lib/minio'
        environment:
          - "MINIO_ACCESS_KEY=development"
          - "MINIO_SECRET_KEY=development"
        ports:
          - "9000:9000"
        command: server /export
      rails:
        build: .
        command: bash -c 'rm -f /test/tmp/pids/server.pid && bundle && bundle exec rails s -p 3000 -b 0.0.0.0'
        volumes:
          - .:/test
        ports:
          - "3000:3000"
        depends_on:
          - minio
    volumes:
      minio:
    

    载波初始值设定项

    CarrierWave.configure do |config|
      config.fog_provider = 'fog/aws'
      config.fog_credentials = {
          provider:              'AWS',
          aws_access_key_id:     'development',
          aws_secret_access_key: 'development',
          region:                'us-east-1',
          host:                  'minio',
          endpoint:              'http://localhost:9000'
      }
      config.fog_directory  = 'test'
      config.fog_public     = false
      # config.fog_attributes = { cache_control: "public, max-age=#{365.day.to_i}" } # optional, defaults to {}
    end
    
    1 回复  |  直到 7 年前
        1
  •  0
  •   Harshavardhana    7 年前

    您的Carrierwave inside docker容器应该指向服务DNS,在您的情况下,以下更改应该可以工作

    CarrierWave.configure do |config|
      config.fog_provider = 'fog/aws'
      config.fog_credentials = {
          provider:              'AWS',
          aws_access_key_id:     'development',
          aws_secret_access_key: 'development',
          region:                'us-east-1',
          host:                  'minio',
          endpoint:              'http://minio:9000'
      }
      config.fog_directory  = 'test'
      config.fog_public     = false
      # config.fog_attributes = { cache_control: "public, max-age=#{365.day.to_i}" } # optional, defaults to {}
    end