skip to Main Content

I want to start my docker container by using python script, but I am using windows while I accessing docker containers in my windows by ‘XSHELL’ terminal using of domain id is (dummy_name.com) and also have a password.

In my script I need while on the lappc automatically the all containers to start and run, by the python script

here my xshell image
here the next password image

after this two process i given to "vim.start.sh" this command then the containers are show the list.

2

Answers


  1. First. You can try using python’s SSH module to go ahead and utilize the code to connect to the host. Here is an example

    pip install paramiko
    

    You can then use the following Python code to connect to the remote host and execute commands:

    import paramiko
    
    # Set the connection information for the remote host
    host = "your_host"
    port = 22
    username = "your_username"
    password = "your_password"
    
    # Establish an SSH connection
    client = paramiko.SSHClient()
    client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    client.connect(hostname=host, port=port, username=username, password=password)
    
    # Command to be executed
    command = "ls -l" # You can replace the command with any command you want to execute
    
    # Execute the command and get the output
    stdin, stdout, stderr = client.exec_command(command)
    
    # Print the output
    print(stdout.read().decode())
    
    # Close the SSH connection
    client.close()
    
    

    The above is an example of connecting to a host using paramiko. You can make changes to the execution command line.
    Please note that this is just a simple example and real applications may require more error handling and security measures. Also, using passwords for SSH connections may not be the most secure practice, and you should consider using SSH keys for authentication.

    Login or Signup to reply.
  2. you can use:

    import os
    
    os.system('docker start [container_id]')
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search