I want to spin up a localstack docker container and run a file, create_bucket.sh, with the command
aws --endpoint-url=http://localhost:4566 s3 mb s3://my-bucket
after the container starts. I tried creating this Dockerfile
FROM: localstack/localstack:latest
COPY create_bucket.sh /usr/local/bin/
ENTRYPOINT []
and a docker-compose.yml file that has
version: '3.8'
services:
localstack:
image: localstack/localstack:latest
environment:
...
ports:
- '4566-4583:4566-4583'
command: sh -c "/usr/local/bin/create_bucket.sh"
but when I run
docker-compose up
the container comes up, but the command isn’t run. How do I execute my command against the localstack container after container startup?
3
Answers
Try by executing below
If you exec into the container, the
create_bucket.sh
is not copied. I’m not sure why and I couldn’t get it to work either.However, I have a working solution if you’re okay to have a startup script as your goal is to bring up the container and execute the creation of the bucket in a single command.
docker-compose.yml
create_bucket.sh
to useawslocal
instead, it is already available in the container. Usingaws
cli with anendpoint-url
needsaws configure
as a pre-req.To verify, if you now
exec
into the running container, the bucket would have been created.You can use mount volume instead of "command" to execute your script at startup container.
Also as they specify in their documentation, localstack must be precisely configured to work with docker-compose.
In your case I guess you are missing some volumes, container name and variables.
Here is an example of a docker-compose.yml found here, which I have more or less adapted to your case
Other sources: