Files
gh-thurstonsand-thurstons-c…/skills/truenas-docker-ops/scripts/docker_exec_python.sh
2025-11-30 09:01:48 +08:00

19 lines
567 B
Bash
Executable File

#!/bin/bash
# Execute Python code inside a Docker container on TrueNAS server
# Usage: docker_exec_python.sh <container_name> <python_code>
set -euo pipefail
if [ $# -ne 2 ]; then
echo "Usage: $0 <container_name> <python_code>" >&2
echo "Example: $0 anypod 'import sys; print(sys.version)'" >&2
exit 1
fi
CONTAINER_NAME="$1"
PYTHON_CODE="$2"
# Execute Python code in container via SSH
# Pass Python code through stdin to avoid nested heredoc escaping issues
echo "$PYTHON_CODE" | ssh truenas docker exec -i "${CONTAINER_NAME}" /app/.venv/bin/python -