2

When I run a docker-compose command on the CLI, it looks like this:

docker-compose up -d my-service
# Recreating my-cluster_my-service_1 ... done

However, capturing the output seems to break it:

foo=$(docker-compose up -d my-service 2>&1)
echo $foo # <-- this line actually vanishes!
# Recreating my-cluster_my-service_1 ... done
#  ecreating my-cluster_my-service_1 ... 

Note how we have to re-direct stderr because, for some reason, docker-compose outputs there instead of stdout.

This makes it hard to handle output of docker-compose programmatically. How can I get the correct output of docker-compose?

1 Answer 1

1

The issue is apparently that docker-compose uses control characters to re-write the printed line. That's fine in an interactive terminal (even though the effect is nil in this case) but capturing (and echoing) a stream containing such characters has unexpected effects like what we see above.

Add option --no-ansi to suppress those control characters:

$ alf=$(docker-compose --no-ansi up -d my-service 2>&1)
$ echo $alf
# Recreating my-cluster_my-service_1 ... done
Sign up to request clarification or add additional context in comments.

Comments

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.