-1

I am trying to run this command with the docker python sdk but I am not sure I am passing the commands in properly. How would I run the command "stress --cpu 4 &" using the docker python sdk?

m = container.exec_run("stress --cpu 4 &")
swalga
  • 11
  • 3
  • Where does `container` come from? What error are you getting? Are you launching this call from within a container, and if so, how are you starting it? Can you provide a [mcve] demonstrating the issue? – David Maze Mar 22 '20 at 18:44
  • when I run this, m = container.exec_run("stress --cpu 1 &"), I get this error ExecResult(exit_code=1, output=b'stress: FAIL: [325] (244) unrecognized option: &\n') – swalga Mar 22 '20 at 20:55

1 Answers1

0

You can just put it in one string

m = container.exec_run("stress --cpu 4")

there are some examples here

if you want to run a command in background, don't use &, use detach=True

m = container.exec_run("stress --cpu 4", detach=True)

Community
  • 1
  • 1
Vahid
  • 1,265
  • 10
  • 20
  • When I try to run the process in the background like this container.exec_run("stress --cpu 1 &"), it gives me this error, ExecResult(exit_code=1, output=b'stress: FAIL: [325] (244) unrecognized option: &\n') – swalga Mar 22 '20 at 20:56