I am very new to server side operations and I want to write an API that starts the training models on GPU server and allows the train outputs to be displayed to client. Since more than one person is connected to the server, we work in docker containers so that the operations we do, do not cause any problems. I want to use the code below in my future API. The code simply connect to main server with ssh. I tried to use Paramiko for that purpose. Then I want to get into my container, activate my anaconda environment in that container and run a python script to start training.
import paramiko
host = "xxx.xx.x.xxx" # actual host IP
username = "support"
password = "password"
client = paramiko.client.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect(host, username=username, password=password)
_stdin, _stdout, _stderr = client.exec_command("pwd")
_stdin.close()
print(_stdout.read().decode()) # It prints the directory in the main server --> /home/support
print(_stderr.read().decode())
_stdin, _stdout, _stderr = client.exec_command("docker exec -it <container id> /bin/bash; pwd")
_stdin.close()
print(_stdout.read().decode()) # It still prints the directory in the main server --> /home/support. I guess it does not get into container.
print(_stderr.read().decode())
_stdin, _stdout, _stderr = client.exec_command("docker exec -it <container id> /bin/bash; conda activate <my conda env>; python train.py") # The real command series that I want to do.
_stdin.close()
print(_stdout.read().decode())
print(_stderr.read().decode()) # It prints the
# input device is not a TTY
# bash: conda: command not found
client.close()
But it does not work like how I imagine. I could not figure out how to get into my container. Since this approach does not work, I also tried to connect the container with ssh, but it did not work either.
My question is how can i perform such the operation I described.