skip to Main Content

I’m a LocalStack/Docker rookie, trying to create a docker-compose.yml file to start a Spring Boot application container + a LocalStack container, I’m not sure if shall I create a network for the containers, and also how to configure the SQS URL in order to make possible to connect my Spring Boot app with SQS running on LocalStack, thanks for your hints.

docker-compose.yml

version: "3.8"
services:
  app:
    build:
      context: .
      dockerfile: Dockerfile
    image: my-spring-app
    container_name: spring-app
    ports:
      - "8080:8080"
    environment:
      - AWS_ACCESS_KEY_ID=12345
      - AWS_SECRET_ACCESS_KEY=12345
    depends_on:
      - localstack
  
  localstack:
    image: localstack/localstack:latest
    container_name: localstack
    environment:
      - SERVICES=sqs
      - DEBUG=1
    ports:
      - "4566:4566"
    volumes:
      - "/tmp/localstack:/tmp/localstack"

application.yml (Spring Boot App)

cloud:
  aws:
    stack:
      auto: false
    region:
      static: us-east-1
      auto: false
    credentials:
      access-key: 12345
      secret-key: 12345
    queue:
      uri: http://localhost:4566
      name: sample-queue.fifo

2

Answers


  1. The Uri should be the service name in your docker-compose.yaml
    In your case:

    **application.yml** (Spring Boot App)
    
        cloud:
          aws:
            stack:
              auto: false
            region:
              static: us-east-1
              auto: false
            credentials:
              access-key: 12345
              secret-key: 12345
            queue:
              uri: http://localstack:4566
              name: sample-queue.fifo
    
    Login or Signup to reply.
  2. Compose automatically creates a network for you; you don’t need to manually specify networks: in your Compose file. Each service is visible to other containers using its Compose service name as a host name, app and localstack. Also see Networking in Compose in the Docker documentation.

    You can set Spring properties using environment variables and in a container environment specifying these environment variables is almost always easier than trying to change a YAML file in your application. You should be able to set:

    version: "3.8"
    services:
      app:
        build: .
        ports:
          - "8000:8000"
        environment:
          - AWS_ACCESS_KEY_ID=12345
          - AWS_SECRET_ACCESS_KEY=12345
          - SPRING_CLOUD_QUEUE_URI=http://localstack:4566  # <-- add this
        depends_on:
          - localstack
    
      localstack: { ... }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search