I would like to write bash script which automates the following:
Get inside running container
docker exec -it CONTAINER_NAME /bin/bash
Execute some commands:
cat /dev/null > /usr/local/tomcat/logs/app.log
exit
The problematic part is when docker exec is executed, new shell is created and other commands are not executed
Is there a way how to solve it?
解决方案
You can use heredoc with docker exec command:
docker exec -i CONTAINER_NAME bash <
cat /dev/null > /usr/local/tomcat/logs/app.log
exit
EOF
To use variables:
logname='/usr/local/tomcat/logs/app.log'
then use as:
docker exec -i CONTAINER_NAME bash <
cat /dev/null > "$logname"
exit
EOF