Reputation: 7012
I am trying to run the fake_sqs gem in a docker container in development to test my SQS integration, and have another app send messages to it.
My docker-compose file looks like this:
app:
build: .
command: bundle exec rails s Puma --port 3000 --binding 0.0.0.0
volumes:
- ./:/app
ports:
- 3000:3000
links:
- db:db
environment:
VIRTUAL_HOST: app.docker
PGHOST: db
PGUSER: postgres
AWS_REGION: us-west-2
AWS_QUEUE_NAME: my-queue
AWS_ENDPOINT: http://aws.docker:4568/
fakesqs:
build: .
command: fake_sqs -p 4568
volumes:
- ./:/app
ports:
- 4568:4568
links:
- db:db
environment:
VIRTUAL_HOST: aws.docker
PGHOST: db
PGUSER: postgres
AWS_REGION: us-west-2
db:
image: postgres
This works to some degree. I can send messages to the fakesqs
using the http://aws.docker:4568
url. The problem I am trying to solve centers around the command for the fakesqs
container. If you run fake_sqs
as it is written in my file, by default it sets the hostname to 0.0.0.0
. This means that when I use the aws-sdk gem to request queue urls, fake_sqs
replies with the wrong host.
client = Aws::SQS::Client.new
client.get_queue_url(queue_name: 'my-queue').queue_url
# => http://0.0.0.0:4568/my-queue
I obviously can't use this url to send messages. Instead, the url needs to be the IP of the fakesqs
container. You can set the host url with the -o
option (i.e. fake_sqs -o <IP_ADDRESS> -p 4568
).
How can I access the fakesqs
container IP address to put into the command? Do I have to set a static IP address for that container? Or is there another way I'm meant to be doing it?
Upvotes: 0
Views: 680
Reputation: 10185
Try to use hostname instead of IP address.
add link to fake_sqs from you app container
app:
build: .
command: bundle exec rails s Puma --port 3000 --binding 0.0.0.0
volumes:
- ./:/app
ports:
- 3000:3000
links:
- db:db
- fake_sqs #add this line!
environment:
VIRTUAL_HOST: app.docker
PGHOST: db
PGUSER: postgres
AWS_REGION: us-west-2
AWS_QUEUE_NAME: my-queue
and try to execute fake_sqs -o fake_sqs -p 4568
inside your app container
Upvotes: 4