I have a simple init.sh script (creating S3 buckets), which needs to be run in the localstack container after it’s ready. Below is my docker compose file
localstack:
image: ....../localstack/localstack:latest
container_name: localstack
ports:
- "4566:4566"
environment:
- SERVICES=s3
- DEBUG=1
- DATA_DIR=
- AWS_REGION=us-east-1
- AWS_DEFAULT_REGION=us-east-1
- AWS_ACCESS_KEY_ID=fake
- AWS_SECRET_ACCESS_KEY=fake
- HOSTNAME=localstack
- HOSTNAME_EXTERNAL=localstack
volumes:
- "${LOCALSTACK_VOLUME_DIR:-./volume}:/var/lib/localstack"
- "/var/run/docker.sock:/var/run/docker.sock"
- "${PWD}/docker-entrypoint-initaws.d/init.sh:/etc/localstack/init/ready.d/init-aws.sh"
However, I got the error below:
Error while running script Script(path="/etc/localstack/init/ready.d/init-aws.sh", stage=READY, state=ERROR)
Traceback (most recent call last):
File "/opt/code/localstack/localstack/runtime/init.py", line 136, in run_stage
runner.run(script.path)
File "/opt/code/localstack/localstack/runtime/init.py", line 69, in run
exit_code = subprocess.call(args=[], executable=path)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/subprocess.py", line 389, in call
with Popen(*popenargs, **kwargs) as p:
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/subprocess.py", line 1026, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "/usr/local/lib/python3.11/subprocess.py", line 1950, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
PermissionError: [Errno 13] Permission denied: '/etc/localstack/init/ready.d/init-aws.sh'
Clearly, it is a permission issue of the init-aws.sh, I checked it, it was -rw-r--r-- 1 root root 341 Dec 8 21:27 /etc/localstack/init/ready.d/init-aws.sh
. Thus, I tried to add
command: chmod +x /etc/localstack/init/ready.d/init-aws.sh && /docker-entrypoint.sh localstack
into my docker compose file to change the mode of the file. But it was not run at all cause I didn’t see it printed out in the localstack log. Plus, the script still have permission issue and failed to run.
Can anyone help? Thanks in advance.