I'm currently using a bind mount to mount a file from the host to a container:
volumes:
- type: bind
source: ./localstack_setup.sh
target: /docker-entrypoint-initaws.d/init.sh
Is there a way to define the ./localstack_setup.sh inline in the docker-compose.yml? I want to use a remote Docker host, and docker-compose up fails because the remote host doesn't have the file.
As of Docker Compose version 2.23.1, released on Nov 15th, 2023 this is now possible. See the release notes for Compose Specification 1.20.1.
name: config-inline
services:
service:
image: ubuntu
entrypoint: cat
command: /path/to/config.txt
configs:
- source: config.txt
target: /path/to/config.txt
configs:
config.txt:
content: |
strawberry fields forever
$ docker-compose up
[+] Building 0.0s (0/0) docker:default
[+] Running 2/0
✔ Network config-inline_default Created 0.0s
✔ Container config-inline-service-1 Created 0.0s
Attaching to service-1
service-1 | strawberry fields forever
service-1 exited with code 0
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With