Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

define inline file in docker-compose

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.

like image 273
Michael Böckling Avatar asked Jun 07 '26 00:06

Michael Böckling


1 Answers

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
like image 175
Tobias Bergkvist Avatar answered Jun 08 '26 15:06

Tobias Bergkvist