2

I have container A that has an environment variable called VAR1 set. If I do

docker-compose exec A env

I get the result

VAR1=VALUE1

Now, I need to pass this VALUE1 to another command (lets call this as command1) in the same container, and I tried the following:

docker-compose exec A command1 $VAR1

Unfortunately, $VAR1 is evaluated in the local machine in which this command is run (remember this environment variable is set only inside container A).

How do I pass on specific container environment variables to commands that I run through docker-compose exec?

0

1 Answer 1

1

You have to execute a shell in the container and pass it the entire command line quoted with single quotes to avoid evaluation on the host :

docker-compose exec A sh -c 'command1 $VAR1'
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.