Can't upload file through carrierwave fog-aws to minio (docker-compose)

1.4k views Asked by At

Have error Excon::Error::Socket (getaddrinfo: Name or service not known (SocketError)) when try to upload file through carrierwave fog-aws to minio.

Docker compose

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 initializer

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
2

There are 2 answers

0
Harshavardhana On BEST ANSWER

You Carrierwave inside docker container should point to the service DNS in your case following change should work

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
0
Ali Akbar Hemmati On

Adding to previous answer you should also add 'path_style' => true to your config