简体   繁体   中英

Run Linux Command inside Docker Container via command line

I have this command

clear; sudo kubectl exec -it $(kubectl get pods | grep 'app' | cut -d ' ' -f 1) ash 

I will land here

/src # 

I want to also run a command ls

/src # ls                                                                                           
Procfile             composer.lock        phpunit.xml          server.php                           
app                  config               public               storage                              
artisan              database             resources            tests                                
benu.code-workspace  heroku.sh            routes               vendor                               
bootstrap            package-lock.json    run.sh               webpack.mix.js                       
composer.json        package.json         scripts                                                   
/src #   

I've tried

clear; sudo kubectl exec -it $(kubectl get pods | grep 'app' | cut -d ' ' -f 1) ash echo "ls"

and

clear; sudo kubectl exec -it $(kubectl get pods | grep 'app' | cut -d ' ' -f 1) echo "ls"

Please correct me

If you want to run the command, you want kubectl exec -it $podname ls . If you put echo "ls" then that is the command which run, ie print "ls".

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM