I want to excute some commands inside a container but the second one doesn't want to be executed inside the container so grep can't find the file in home directory of my container. Does someone has the same problem?

# Throughput
    docker exec -i container_client bash << EOF >> mystatistics.xls
    (sockperf throughput --tcp --msg-size=256 -i $ipaddcontainer -p 12345 -t 10)> my_output_file_troughput.txt
    echo "Bridge mode" "," `grep 'BandWidth is ' my_output_file_troughput.txt | cut -d ' ' -f 5`

When you use here-docs, you should remember about the difference when quoting or not quoting the EOF token. Without qoutes, any command substitution will be executed in the main shell, not in Docker. Compare these two:

$ cat <<EOF
$(echo ok)



$ cat <<"EOF"
$(echo ok)

$(echo ok)

So if you want to pass commands including command substitution to Docker, you should quote the token.

By the way,

  1. Why are you using a subshell for sockperf btw?
  2. The ticks are obsolete and the new syntax is $().

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.