Search code examples
dockerdocker-composelocalstack

Localstack [Errno 8] Exec format error: '/etc/localstack/init/ready.d/setup.sh'


I know there are a litany of other SO questions on this topic but I have tried all of the suggestions to no avail.

Environment I am running this on is Windows 10 Professional.

setup.sh

#!/bin/bash

echo "Creating SQS queue"
awslocal sqs create-queue --queue-name my-queue

Localstack.Dockerfile

FROM localstack/localstack:3.2

COPY --chown=localstack localstack-scripts/setup.sh /etc/localstack/init/ready.d/setup.sh

RUN chmod u+x /etc/localstack/init/ready.d/setup.sh

docker-compose.yml

version: '3.4'

services:
  document-db:
    image: mysql:8.0
    container_name: document-db
    environment:
      MYSQL_ROOT_PASSWORD: "mysql"
      MYSQL_PASSWORD: "password"
      MYSQL_DATABASE: "document-db"
      MYSQL_USER: "user"
    volumes:
      - ./data:/var/lib/mysql
    ports:
      - "3306:3306"
  localstack:
    build:
      context: .
      dockerfile: /localstack-scripts/LocalStack.Dockerfile
    environment:
      - SERVICES=sqs,sns
      - AWS_DEFAULT_REGION=eu-west-2
    container_name: localstack
    ports:
      - "127.0.0.1:4566:4566"            # LocalStack Gateway
      - "127.0.0.1:4510-4559:4510-4559"  # external services port range

When I run docker-compose up I get the following error:

localstack   | 2024-03-20T14:51:09.634 ERROR --- [  MainThread] localstack.runtime.init    : Error while running script Script(path='/etc/localstack/init/ready.d/setup.sh', stage=READY, state=ERROR): [Errno 8] Exec format error: '/etc/localstack/init/ready.d/setup.sh'
Gracefully stopping... (press Ctrl+C again to force)

I have ensured that all the line endings on the setup.sh files are LF and I have even used https://app.execeratics.com/LFandCRLFonline/?l=en to convert the file, but to no avail.

At this point I am so close, but so far.

Any pointers?


Solution

  • I resolved the problem by creating my setup.sh from the WSL2 command line in the end.

    echo '#!/bin/bash' > localstack-scripts/setup.sh
    echo '' >> localstack-scripts/setup.sh
    echo 'echo "Creating SQS queue"' >> localstack-scripts/setup.sh
    echo 'awslocal sqs create-queue --queue-name my-queue' >> localstack-scripts/setup.sh
    

    It appears that https://app.execeratics.com/LFandCRLFonline/?l=en wasn't doing what I hoped it would do.