Lossan
Lossan

Reputation: 441

How to run Docker from php?

I am a beginner in using Docker, and I am trying to run docker from php, specifically I need to run openface code. I used the command lines provided here https://cmusatyalab.github.io/openface/setup/ to make sure that docker is running on my pc correclty and it works. but now I need to call it from PHP, I wrote the same commands in batch file as follows

docker run -p 9000:9000 -p 8000:8000 -t -i bamos/openface /bin/bash
cd /root/openface
./demos/compare.py images/examples/{lennon*,clapton*}
pause

and tried to execute it in php by calling

echo shell_exec ("test.bat");

but when I run the batch file directly, only the first line is executed. as it seems the next command is not being executed inside the docker container.

cmd screen

how can I make all commands execute? any help will be very much appreciated, thank you

Upvotes: 0

Views: 162

Answers (1)

Tarun Lalwani
Tarun Lalwani

Reputation: 146510

The problem is the first bash won't exit before you exit it and the rest of the commands are interpreted by host bash.

What you need is that your work is done and then you get inside a bash (inside the container)

docker run -p 9000:9000 -p 8000:8000 -t -i bamos/openface /bin/bash -c "cd /root/openface && ./demos/compare.py images/examples/{lennon*,clapton*} && exec bash"

First "bash -c" is to execute the commands and last command exec bash override the main bash and gives you a shell

Upvotes: 2

Related Questions