Connecting inside container at docker environment using JSCH -
i developing java application connect (using ssh) linux machine attach docker container , send commands on that.
now, able connect linux machine, send commands , read responses, when try attach container , send commands inside it, nothing received , not able send commands.
i usinf code below. please me issue?
try{ jsch jsch=new jsch(); string host=null; if(arg.length>0){ host=arg[0]; } else{ host=joptionpane.showinputdialog("enter username@hostname", "root@10.46.68.147"); } string user=host.substring(0, host.indexof('@')); host=host.substring(host.indexof('@')+1); session session=jsch.getsession(user, host, 22); //session session=jsch.getsession("root", "10.46.68.147", 4184); // username , password given via userinfo interface. userinfo ui=new myuserinfo(); session.setuserinfo(ui); session.connect(); string temp = ""; string all_content = "docker ps -a;docker attach 9071d6cda4d8;client" //open session , send commands channel channel=session.openchannel("exec"); ((channelexec) channel).setpty(true); //command running groove containers channel.setxforwarding(true); ((channelexec)channel).setcommand(all_content); channel.setinputstream(null); ((channelexec)channel).seterrstream(system.err); inputstream in=channel.getinputstream(); channel.connect();
Comments
Post a Comment