sneakers workers "could not translate host name "postgres" to address: Name or service not known

I get this error “could not translate host name “postgres” to address: Name or service not known, while trying to call a model inheriting from ActiveRecord::Base, in a sneakers workers.

We have rabbitmq and app server running in docker containers. If I do ‘rails c’ from the app container and access the model data, it works. But when the same code is called from the sneakers worker, it throws the error.

class MarketServer
  include Sneakers::Worker
  from_queue 'some_queue',
             env: nil,
             timeout_job_after: 12.hours

  def work_with_params(msg, _headers, params)
    begin
      data = {}
      ActiveRecord::Base.connection_pool.with_connection do
        data['market_name'] = Market.last.name
      end
      Rails.logger.debug 'data built'

      ack! # we need to let queue know that message was received
  end
end

Source: StackOverflow