-3

This issue occurs only on the Windows version of Docker (I'm running Windows 10, docker 20.10.17). I have a shell script I'd like to run after my docker container is built.

It's named my_script.sh and contains:

aws --endpoint-url=http://localhost:4566 s3 mb s3://my-bucket

My docker-compose.yml file is:

version: '3.8'
services:
  localstack:
    image: localstack/localstack:latest
    environment:
      - DEFAULT_REGION=ap-northeast-2
      ...
    ports:
      - '4566-4583:4566-4583'
    volumes:
      - ./my_script.sh:/docker-entrypoint-initaws.d/my_script.sh

On Mac/Linux versions of Docker, this runs correctly when using docker-compose up.

However, on the Windows version, it errors out with:

...
localstack_1  | Ready.
localstack_1  | /usr/local/bin/docker-entrypoint.sh: running /docker-entrypoint-initaws.d/my_script.sh
 Parameter validation failed:ailed: s3://my-bucket
": Bucket name must match the regex "^[a-zA-Z0-9.\-_]{1,255}$" or be an ARN matching the regex "^arn:(aws).*:(s3|s3-object-lambda):[a-z\-0-9]*:[0-9]{12}:accesspoint[/:][a-zA-Z0-9\-.]{1,63}$|^arn:(aws).*:s3-outposts:[a-z\-0-9]+:[0-9]{12}:outpost[/:][a-zA-Z0-9\-]{1,63}[/:]accesspoint[/:][a-zA-Z0-9\-]{1,63}$"

It's as if Windows is running this script in its own Command Prompt rather than a shell.

How do I get Windows to interpret the script as a shell script?

Ermiya Eskandary
  • 15,323
  • 3
  • 31
  • 44
Dave
  • 15,639
  • 133
  • 442
  • 830

1 Answers1

1

You may have potential CRLF (Windows) line endings in your my_script.sh file if you've opened and saved the file on Windows, which Bash (the script interpreter) won't like.

You'll need to convert them to LF (Linux) line endings which you can do in many ways - feel free to Google. An easy and quick way would be to use this minimal online tool or dos2unix, both of which can do the conversion for you.

After converting & replacing the file locally, make sure you don't accidentally checkout the file in Git etc. which might automatically convert the line endings back to CRLF.

Ensure your user has full privileges to read & execute the file in Windows (chmod +x script.sh on Unix).


Please note the /docker-entrypoint-initaws.d directory usage is also now deprecated and will be removed in the LocalStack 2.0 release. For future-proofing, I recommend using /etc/localstack/init/ready.d instead, which would let you hook into the 'READY` stage.

Ermiya Eskandary
  • 15,323
  • 3
  • 31
  • 44
  • Running "dos2unix my_script.sh" does clean up the line endings and eliminate the error I'm seeing. But regarding changing " - ./my_script.sh:/docker-entrypoint-initaws.d/my_script.sh" to "./my_script.sh:/etc/localstack/init/ready.d/my_scriptt.sh", the error "2022-12-18T18:33:22.408 ERROR --- [ MainThread] localstack.runtime.init : Error while running script Script(path='/etc/localstack/init/ready.d/my_script.sh', stage=READY, state=ERROR): [Errno 8] Exec format error: '/etc/localstack/init/ready.d/my_script.sh' is appearing upon running "docker-compose up". – Dave Dec 18 '22 at 18:39
  • Great, so that solved your question! Regarding your other error, I notice ‘scriptt.sh’ and not ‘script.sh’ in your error. Have you misspelled anything? Ensure the file is executable from within the file properties on Windows (`chmod +x my_script.sh` on Linux. If that doesn't work, I would appreciate [accepting](https://meta.stackexchange.com/a/5235/1081259) my answer and opening up a new one regarding hooks. – Ermiya Eskandary Dec 18 '22 at 19:07