| name | dockergento-shell-executor |
| description | Executes shell commands inside Dockergento containers using hm bash and hm exec. Use when running PHP scripts, CLI commands, composer operations, or debugging container environments. |
| allowed-tools | Read Grep Glob Bash Edit Write |
| model | sonnet |
Dockergento Shell Executor
Provides shell access to Dockergento containers via hm bash and hm exec commands for executing PHP scripts, Magento CLI commands, composer operations, and container debugging.
When to Use
- Running Magento CLI commands
- Executing PHP scripts
- Composer dependency management
- Container environment inspection
- File system operations
- Debugging container state
- Running custom scripts
- Database operations (via CLI)
- Cache operations
- Module management
Requirements
Execution Workflow
-
Identify operation
- Determine target container (default: php)
- Plan command execution
- Check for dependencies
- Consider working directory
-
Choose execution method
hm bash: Interactive shell or single command
hm exec: Direct command execution
- Consider output handling
-
Execute command
- Run via appropriate method
- Capture output if needed
- Handle errors properly
- Log execution results
-
Verify results
- Check command exit code
- Validate output
- Verify side effects
- Document outcomes
Command Reference
Basic Shell Access
hm bash
hm bash <command>
hm bash php -v
hm bash ls -la
hm bash pwd
Execute Commands
hm exec <command>
hm bash -c <container> <command>
hm bash php bin/magento cache:flush
hm bash composer install
hm bash -c nginx nginx -v
Container Selection
hm bash php -v
hm bash -c nginx nginx -t
hm bash -c varnish varnishd -V
hm bash -c mysql mysql --version
hm bash -c redis redis-cli --version
hm bash -c elasticsearch curl localhost:9200
Implementation Patterns
Pattern 1: Magento CLI Commands
#!/bin/bash
set -e
echo "Running Magento operations..."
echo "Flushing cache..."
hm bash php bin/magento cache:flush
echo "Enabling custom modules..."
hm bash php bin/magento module:enable Vendor_Module
hm bash php bin/magento setup:upgrade
echo "Running compilation..."
hm bash php bin/magento setup:di:compile
echo "Deploying static content..."
hm bash php bin/magento setup:static-content:deploy -f
echo "Running reindex..."
hm bash php bin/magento indexer:reindex
echo "Magento operations completed"
Pattern 2: Composer Management
#!/bin/bash
set -e
OPERATION="${1:-install}"
echo "Running composer ${OPERATION}..."
case "${OPERATION}" in
install)
hm bash composer install --no-interaction
;;
update)
hm bash composer update --no-interaction
;;
require)
PACKAGE="${2}"
if [ -z "${PACKAGE}" ]; then
echo "Usage: $0 require <package>"
exit 1
fi
hm bash composer require "${PACKAGE}"
;;
remove)
PACKAGE="${2}"
if [ -z "${PACKAGE}" ]; then
echo "Usage: $0 remove <package>"
exit 1
fi
hm bash composer remove "${PACKAGE}"
;;
validate)
hm bash composer validate
;;
diagnose)
hm bash composer diagnose
;;
*)
echo "Unknown operation: ${OPERATION}"
exit 1
;;
esac
echo "Composer ${OPERATION} completed"
Pattern 3: PHP Script Execution
#!/bin/bash
set -e
SCRIPT="${1}"
if [ -z "${SCRIPT}" ]; then
echo "Usage: $0 <script.php>"
exit 1
fi
if [ ! -f "${SCRIPT}" ]; then
echo "ERROR: Script not found: ${SCRIPT}"
exit 1
fi
echo "Executing PHP script: ${SCRIPT}"
hm bash php "${SCRIPT}"
echo "Script execution completed"
Pattern 4: Environment Inspection
#!/bin/bash
set -e
echo "=== Dockergento Environment Inspection ==="
echo ""
echo "PHP Version:"
hm bash php -v
echo ""
echo "PHP Modules:"
hm bash php -m | sort
echo ""
echo "Composer Version:"
hm bash composer --version
echo ""
echo "Magento Version:"
hm bash php bin/magento --version
echo ""
echo "Database Connection:"
hm bash php bin/magento setup:db:status
echo ""
echo "Redis Connection:"
hm bash -c redis redis-cli ping
echo ""
echo "Elasticsearch Status:"
hm bash -c elasticsearch curl -s localhost:9200/_cluster/health?pretty
echo ""
echo "Disk Usage:"
hm bash df -h /var/www/html
echo ""
echo "Memory Usage:"
hm bash free -h
echo ""
echo "Environment inspection completed"
Pattern 5: Batch Operations
#!/bin/bash
set -e
echo "Running batch operations..."
COMMANDS=(
"php bin/magento cache:flush"
"php bin/magento setup:upgrade"
"php bin/magento setup:di:compile"
"php bin/magento indexer:reindex"
"php bin/magento cron:run"
)
for cmd in "${COMMANDS[@]}"; do
echo "Executing: ${cmd}"
if hm bash ${cmd}; then
echo "✓ Success: ${cmd}"
else
echo "✗ Failed: ${cmd}"
exit 1
fi
echo ""
done
echo "All batch operations completed successfully"
Advanced Usage
Working Directory Control
hm bash "cd /var/www/html/vendor && ls -la"
hm bash "cd /tmp && php test.php && rm test.php"
Environment Variables
hm bash "MAGE_MODE=developer php bin/magento cache:flush"
hm bash "XDEBUG_MODE=debug php -d memory_limit=4G bin/magento setup:upgrade"
Output Redirection
hm bash php bin/magento module:status > module_status.txt
hm bash "php bin/magento module:status > /tmp/status.txt"
docker cp dockergento_php:/tmp/status.txt ./
Error Handling
#!/bin/bash
set -e
if hm bash php bin/magento setup:upgrade 2>&1 | tee upgrade.log; then
echo "✓ Upgrade successful"
else
echo "✗ Upgrade failed - check upgrade.log"
exit 1
fi
hm bash php bin/magento setup:db:status
EXIT_CODE=$?
if [ ${EXIT_CODE} -eq 0 ]; then
echo "Database is up to date"
else
echo "Database needs upgrade"
fi
Common Operations
Cache Management
hm bash php bin/magento cache:flush
hm bash php bin/magento cache:flush config layout
hm bash php bin/magento cache:enable
hm bash php bin/magento cache:disable
hm bash php bin/magento cache:clean
Module Management
hm bash php bin/magento module:status
hm bash php bin/magento module:enable Vendor_Module
hm bash php bin/magento module:disable Vendor_Module
hm bash php bin/magento module:uninstall Vendor_Module
Indexer Management
hm bash php bin/magento indexer:status
hm bash php bin/magento indexer:reindex
hm bash php bin/magento indexer:reindex catalog_product_price
hm bash php bin/magento indexer:set-mode schedule
Configuration Management
hm bash php bin/magento config:show web/secure/base_url
hm bash php bin/magento config:set web/secure/base_url "https://example.com/"
hm bash php bin/magento config:delete web/secure/base_url
Cron Management
hm bash php bin/magento cron:run
hm bash php bin/magento cron:install
hm bash php bin/magento cron:remove
File Operations
File Permissions
hm bash chmod -R 775 var generated pub/static pub/media
hm bash chown -R www-data:www-data var generated pub/static pub/media
hm bash ls -la var/ generated/ pub/
File Editing
hm bash vi app/etc/env.php
hm bash nano app/etc/env.php
hm bash cat app/etc/env.php
hm bash grep -r "search_term" app/code/
File Transfer
docker cp local_file.php dockergento_php:/var/www/html/
docker cp dockergento_php:/var/www/html/var/log/system.log ./
docker cp ./app/code/Vendor dockergento_php:/var/www/html/app/code/
Debugging Commands
Check PHP Configuration
hm bash php -i | grep "Configuration File"
hm bash php -i | grep memory_limit
hm bash php -m
hm bash php -m | grep xdebug
Check Database Connection
hm bash php -r "new PDO('mysql:host=mysql;dbname=magento', 'magento', 'magento');"
hm bash php bin/magento setup:db:status
Check Redis Connection
hm bash -c redis redis-cli ping
hm bash -c redis redis-cli info
hm bash -c redis redis-cli monitor
Check Logs
hm bash tail -f var/log/system.log
hm bash tail -f var/log/exception.log
hm bash tail -f var/log/debug.log
hm bash tail -f var/log/*.log
Performance Optimization
Profile PHP Execution
time hm bash php bin/magento indexer:reindex
hm bash php -d memory_limit=-1 bin/magento setup:upgrade
Parallel Execution
#!/bin/bash
hm bash php bin/magento indexer:reindex catalog_category_product &
hm bash php bin/magento indexer:reindex catalog_product_category &
hm bash php bin/magento indexer:reindex catalog_product_price &
wait
echo "All indexers completed"
Testing Integration
Run Unit Tests
hm bash vendor/bin/phpunit -c dev/tests/unit/phpunit.xml.dist
hm bash vendor/bin/phpunit app/code/Vendor/Module/Test/Unit/
Run Integration Tests
hm bash vendor/bin/phpunit -c dev/tests/integration/phpunit.xml.dist
hm bash vendor/bin/phpunit dev/tests/integration/testsuite/Magento/Catalog/
Code Quality
hm bash vendor/bin/phpcs --standard=Magento2 app/code/Vendor/Module/
hm bash vendor/bin/phpmd app/code/Vendor/Module/ text cleancode,codesize,design
hm bash vendor/bin/phpstan analyse app/code/Vendor/Module/
Best Practices
- Use
hm bash for single commands (simpler syntax)
- Use interactive mode for exploration (
hm bash without args)
- Always check exit codes for error handling
- Capture output when needed for logging
- Set working directory explicitly when needed
- Use proper error handling in scripts
- Document complex operations with comments
- Test commands in development first
- Use absolute paths when possible
- Clean up temporary files after operations
Common Pitfalls
❌ Don't
- Don't run destructive commands without backup
- Don't ignore exit codes in scripts
- Don't hard-code container names (use
hm)
- Don't assume working directory
- Don't forget to handle errors
- Don't run long operations without logging
✅ Do
- Do backup before destructive operations
- Do check exit codes and handle errors
- Do use
hm commands for portability
- Do specify working directory explicitly
- Do implement proper error handling
- Do log important operations
Troubleshooting
Command Not Found
hm bash which php
hm bash which composer
hm bash echo $PATH
hm bash /usr/local/bin/php -v
Permission Denied
hm bash whoami
hm bash ls -la <file>
hm bash chmod +x <file>
docker exec -u root dockergento_php <command>
Working Directory Issues
hm bash pwd
hm bash "cd /var/www/html && <command>"
hm bash php /var/www/html/bin/magento cache:flush
Quality Bar
- Commands execute without errors
- Exit codes checked and handled
- Output captured when needed
- Errors logged appropriately
- Working directory managed correctly
- Permissions respected
- Container state verified
- Operations documented
- Scripts tested thoroughly
- Team trained on usage