Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

command output interpolation in docker-compose.yml #12275

Open
rino1 opened this issue Nov 8, 2024 · 2 comments
Open

command output interpolation in docker-compose.yml #12275

rino1 opened this issue Nov 8, 2024 · 2 comments
Assignees

Comments

@rino1
Copy link

rino1 commented Nov 8, 2024

Description

Hello everyone, here is my scenario

+ lsb_release -a
Description:	Ubuntu 24.04.1 LTS

+ bash --version
GNU bash, versione 5.2.21(1)-release (x86_64-pc-linux-gnu)

+ cat docker-compose.yml
services:
    composer:
        image: bash/bash
        environment:
            # INTERPOLATED: NO
            NEW_DATE: $(date)
            # INTERPOLATED: YES
            NEW_PATH: $PATH

Let's do some tests

# echo command output
+ echo $(date)
ven 8 nov 2024, 07:31:58, CET

OK, but...

+ docker compose config | grep NEW
      NEW_DATE: $$(date)
      NEW_PATH: /usr/local/sbin:/usr/local/bin:/usr/sbin...etc...etc...

As you can see, $(date) is not interpolated (evaluated).

Is it a bug?
Is it a feature not implemented?
Or am I doing something wrong?

@ndeloof
Copy link
Contributor

ndeloof commented Nov 8, 2024

Docker Compose interpolates variables set by environment (or .env file) using a bash-like ${VAR} syntax, but this is definitely not just a full bash implementation and it does not support sub-command execution ($(command)) - and never will, as this would just break portability (how can you guarantee all system will have this command installed, with a consistent version and output?)

see https://docs.docker.com/compose/how-tos/environment-variables/variable-interpolation/

What's your actual use-case ? To access current date your container can just run date on its own, or equivalent syscall from application code.

@rino1
Copy link
Author

rino1 commented Nov 9, 2024

thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants