How do you compile a yaml file using a bash code?

In my .sh file I write:

if [ "$SERVER" = "1" ]; then
    export CERTIFICATO=certificatesresolvers.leresolver.acme.caServer=https://acme-staging-v02.api.letsencrypt.org/directory
elif [ "$SERVER" = "2" ]; then
    export CERTIFICATO=
else
    echo "Scelta effettuata non corretta!"
fi

In my .yaml file I write:

version: "3.9"

services:
  traefik:
    ...
    command:
      - --log.level=INFO
      ... etc...
      - --${CERTIFICATO}
      ... etc...
    volumes:
      ... etc...
    ports:
      ... etc...
    labels:
      ... etc...

I would like to use only one yaml file for localhost and for mydomain.it. Why is my system not working? How can I do to solve?

Thank you

I am wondering what answer do you expect. Note that if you don’t share enough information you have much less chance to get any reaction. I don’t see any compiling or using the compose command, and you didn’t share any error messages or what you expected and what happened instead so I didn’t really understand the question first. While I was writing the reply I looked at your code so long I realized what you probably want to achieve.

You can use custom compose files (Check docker compose --help for details) and by default you can have docker-compose.yml and docker-compose.override.yml automatically detected by compose. In case of Compose v2, you can also have compose.yml and probably compose.override.yml.

Regarding your shell script, as I mentioned I can’t see any compose command so I don’t know if that is executed in the same script or you just run the shell script and after that you run the compose command in the same shell. In that case you need to source the script and not just execute it.

Example.

source my.sh

docker compose up -d
1 Like

The question is simple, the solution very complex. The problem is the blank line. I don’t know how to write a comment in bash code.
With bash code I can write this:
Case 1
- --certificatesresolvers.leresolver.acme.storage=/letsencrypt/acme.json
Case 2
- --
but I can’t write this:
Case 1
- --certificatesresolvers.leresolver.acme.storage=/letsencrypt/acme.json
Case 2
#- --certificatesresolvers.leresolver.acme.storage=/letsencrypt/acme.json
I need a strategy to clear the row when in production.
This piece of code is wrong:
- --
Happy Christmas @rimelek !

You can’t remove anything. You can use another yaml in which you define only the comand with different value.

https://docs.docker.com/compose/extends/#multiple-compose-files

The question is simple, the solution very complex. The problem is the blank line. I don’t know how to write a comment in bash code.

Comments in bash are lines preceded by a # sign:

# This is a comment