Как запускать команды оболочки внутри контейнера докеров?Python

Программы на Python
Ответить Пред. темаСлед. тема
Гость
 Как запускать команды оболочки внутри контейнера докеров?

Сообщение Гость »

Код: Выделить всё

import docker

# Initialize the Docker client
client = docker.from_env()

# Define Docker run options
docker_run_options = {
'name': 'container-name',
'user': 'dafoamuser',
'mounts': [
{
'type': 'bind',
'source': 'D:/Dafoam/oneraM6',
'target': '/home/dafoamuser/mount'
}
],
'working_dir': '/home/dafoamuser/mount',
'detach': True,
'tty': True,
'stdin_open': True,
'command': 'bash'
}

# Run the Docker container with specified options
container = client.containers.run(
'dafoamimage:latest',
**docker_run_options
)

# Execute the mpirun command inside the container
mpirun_command = 'mpirun -np 8 python runScript_v2.py 2>&1 | tee logOpt.txt'
exec_cmd = container.exec_run(mpirun_command, tty=True, privileged=True)
print(f"Command: {mpirun_command}\nOutput:\n{exec_cmd.output.decode('utf-8')}")

# Stop and remove the container (if needed)
container.stop()
container.remove()
Я пытаюсь выполнить скрипт Python с именем runScript_v2.py внутри оболочки контейнера, используя приведенный выше скрипт Python.
Но получаю следующую ошибку:

Код: Выделить всё

C:\Users\yesbo\.conda\envs\py39env\lib\site-packages\paramiko\transport.py:219: CryptographyDeprecationWarning: Blowfish has been deprecated
"class": algorithms.Blowfish,
Command: mpirun -np 8 python runScript_v2.py 2>&1 | tee logOpt.txt
Output:
--------------------------------------------------------------------------
mpirun was unable to find the specified executable file, and therefore
did not launch the job.  This error was first reported for process
rank 0; it may have occurred for other processes as well.

NOTE: A common cause for this error is misspelling a mpirun command
line parameter option (remember that mpirun interprets the first
unrecognized command line token as the executable).

Node:       c537205732b5
Executable: python
--------------------------------------------------------------------------
8 total processes failed to start
Как это исправить? Из cmd я могу легко запустить эту команду mpirun без каких-либо ошибок. Но когда я запускаю скрипт Python, он выдает ошибку.

Подробнее здесь: https://stackoverflow.com/questions/781 ... -container
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение

Вернуться в «Python»