How to run 2 commands with docker exec

This led to the answer: Escape character in Docker command line I ended up doing this:

sudo docker exec boring_hawking bash -c 'cd /var/log ; tar -cv ./file.log' | tar -x

So it works by, sort of, running the one bash command with a parameter that is the 2 commands I want to run.


Quite often, the need for several commands is to change the working directory — as in the OP's question.

For that, docker now has a -w option to specify the working directory. E.g. in the present case

docker exec -w /var/log boring_hawking tar -cv ./file.log

Tags:

Docker