0

I am converting docker containers into Custom Apps of TrueNAS 25.04 managing them in the WebUI. It should prevent iX from messing them unnoticeably.

A Custom App can be created from filling in the content of compose.yaml in the WebUI. I have no control about the environment variables it may load nor the directory the compose.yaml runs from. Hence I need some variables for saving me from repeating the required directories and files in the “compose.yaml” field. It helps me to deploy them onto various machines as well.

Here is my question: Is there a way to concatenate alias in a docker compose file?

For example, a docker compose file as following:

services:
  glances:
    image: nicolargo/glances:latest
    container_name: glances
    pid: host
    network_mode: host
    environment:
      - "TZ=Europe/London"
      - "GLANCES_OPT=-C /config/glances.conf -w"
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock:ro
      - /docker/glances/config:/config:ro
      - /docker/glances/data:/data:ro
    restart: unless-stopped

I would like to convert it to something as the following:

x-var: &home /docker/glances

services:
  glances:
    image: nicolargo/glances:latest
    container_name: glances
    pid: host
    network_mode: host
    environment:
      - "TZ=Europe/London"
      - "GLANCES_OPT=-C /config/glances.conf -w"
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock:ro
      - !join [*home, "/config:/config:ro"]
      - !join [*home, "/data:/data:ro"]
    restart: unless-stopped

Is it possible?

6
  • Please Edit the question and remove all the code that is not relevant to this question, in other words you can remove the code duplicated in both examples. Commented Sep 28 at 19:23
  • What does *home mean? The first example doesn’t contain home, so I’m not sure to understand the goal here. Commented Sep 28 at 19:25
  • It was the directory the file compose.yaml was in. However, I am converting it into a Custom App for TrueNAS SCALE 25.04. Hence I can no longer to use my own directory. I am trying to find a way to get around it. truenas.com/docs/scale/25.04/scaleuireference/apps/… Commented Sep 29 at 20:49
  • Please Edit the question and add that the goal is to support TrueNAS, it may have an impact on the solution, if there is one. Commented Sep 30 at 1:28
  • Since it mentions a server, this question may be more appropriate on serverfault.com since there is a relevant tag: serverfault.com/questions/tagged/truenas Commented Sep 30 at 1:29

1 Answer 1

2

Other than some limited capabilities around environment-variable substitution, neither Docker Compose nor the underlying YAML format has any string-formatting capabilities. The environment-variable substitution happens pretty much everywhere, though, including in volumes:, so that might be enough for you:

volumes:
  - "${DATA_DIR:-.}/config:/config:ro"
  - "${DATA_DIR:-.}/data:/data:ro"

Note, as I show in the defaults here, that Compose can use relative paths for volumes:, relative to the directory containing the Compose file. IME if you need to inject local storage, just using the directory the Compose file is in is a much more common setup than trying to allow an arbitrary other host directory.

Sign up to request clarification or add additional context in comments.

2 Comments

(If you need the host pid namespace, host networking, access to an arbitrary host directory, and unrestricted control over the host via the Docker socket, running your process as root without a container might be easier.)
Thanks a lot mate. I knew that the "./" is the directory where the compose.yaml is located. I am trying to convert a compose container into a Custom App in TrueNAS 25.04. I lost control where to put the compose.yaml file in this process. Nor the environment variables for the middleware. That's why I would like to put a variable for the stuff was on the original location. It is unfortunate that cannot not be done with a compose.yaml. :( truenas.com/docs/scale/25.04/scaleuireference/apps/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.