0

I'm trying to run

docker-compose --env-file <(cat file1.env <(echo -e "\n\n") file2.env) config 

docker-compose expects --env-file to be a file. I need to use (concatenate) two files.

Running docker-compose --env-file file_any.env config works well.

Running cat file1.env <(echo -e "\n\n") file2.env separately outputs valid result.

But it somehow doesn't work with docker-compose.

What am I doing wrong?

4
  • Is there an error message? Commented Jun 1, 2020 at 14:08
  • No, docker-compose doesn't issue any errors in cases there's no file or it is empty, only can judge on the output not having variables defined in .env files. Commented Jun 1, 2020 at 14:14
  • Creating a temporary file in /tmp or /dev/shm (if available) is not an option? Commented Jun 1, 2020 at 14:22
  • @Cyrus, it is, but not the desired one. Commented Jun 1, 2020 at 14:36

1 Answer 1

2

You don't need an additional process substitution. The outer process substitution captures the standard output of all the commands it wraps, so you aren't limited to a single cat command.

docker-compose --env-file <( cat file1.env; printf '\n\n'; cat file2.env) config 

Unfortunately, docker-compose requires the argument to --env-file be a real file. The value of the argument is passed directly to Environment.from_env_file, which makes an explicit check via env_vars_from_file:

def env_vars_from_file(filename, interpolate=True): """ Read in a line delimited file of environment variables. """ if not os.path.exists(filename): raise EnvFileNotFound("Couldn't find env file: {}".format(filename)) elif not os.path.isfile(filename): raise EnvFileNotFound("{} is not a file.".format(filename)) ...
Sign up to request clarification or add additional context in comments.

6 Comments

Doesn't work, neither --env-file <(cat file.env) does
If --env-file <(cat file.env) doesn't work, then docker-compose expects a seekable file handle and you can't use process substitution, period.
@disfated sure script runs in bash?
@alecxs, pretty sure. @chepner is probably right since docker-compose is only a wrapper and passes its options down to docker so it can further spawn containers. It makes sense that it doesn't like what process substitution produces, what I suppose to be some kind of ephemeral file descriptor.
I've updated the answer with evidence that a process substitution cannot work. This appears to be a restriction inherited from pypi.org/project/python-dotenv, which does the actual parsing. I didn't dig into dotenv enough to see if that's a necessary restriction, or if it actually could read from a /dev/fd file (it may be restricting itself too much).
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.