2

I have docker running on Host. There are two docker containers on this host i.e container_1 and container_2. Now I want to execute some commands on container_1 from my remote dev machine.

pipe separated commands i.e,

sudo docker exec -it  container_1 sudo find <dir> - type f -iname *_abc_* -print0 | du --files0-from - -b | awk 'BEGIN{sum=0} {sum+=$1} END{print sum}'

Form above command only first command till first pipe execute on docker container and next set of command execute on host.

I am using python fabric api to execute this from remote machine.

Is there any way to execute this full command on container from remote machine ?

3
  • 1
    that's because pipe command actually gets executed on your host, try this, it may work for you: sudo docker exec -it container_1 bash -c "sudo find - type f -iname _abc_ -print0 | du --files0-from - -b | awk 'BEGIN{sum=0} {sum+=$1} END{print sum}'" Commented Dec 27, 2015 at 4:47
  • @Boynux, it works for me. Thank you. Commented Dec 27, 2015 at 10:24
  • I'll create an Answer for that, it'd be great if you mark it a correct answer. Commented Dec 27, 2015 at 12:37

1 Answer 1

5

That's because pipe command actually gets executed on your host, try this, it may work for you:

sudo docker exec -it container_1 bash -c "sudo find - type f -iname_abc_ -print0 | du --files0-from - -b | awk 'BEGIN{sum=0} {sum+=$1} END{print sum}'"
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.