user2626210
user2626210

Reputation: 125

Running a script in docker container and not killing the script when leaving terminal

I have got some docker container for instance my_container I Want to run a long living script in my container, but not killing it while leaving the shell

I would like to do something like that

docker exec -ti my_container /bin/bash 

And then

screen -S myScreen 

Then

Executing my script in screen and exit the terminal

Unfortunately, I cannot execute screen in docker terminal

Upvotes: 6

Views: 10714

Answers (3)

LPCTSTR
LPCTSTR

Reputation: 21

this maybe help you.

docker exec -i -t c2ab7ae71ab8 sh -c "exec >/dev/tty 2>/dev/tty </dev/tty && /usr/bin/screen -r nmsrv -s /bin/bash"    

and this is the reference link

Upvotes: 2

Eli
Eli

Reputation: 39009

If you have to run the script directly in an already running container, you can do that with exec:

docker exec my_container /path/to/some_script.sh

or if you wanna run it through Php:

docker exec my_container php /path/to/some_script.php

That said, you typically don't want to run scripts in already running containers, but to just use the same image as some already running container. You can do that with a standard docker run:

docker run -a stdout --rm some_repo/some_image:some_tag php /path/to/some_script.php

Upvotes: 0

East2West
East2West

Reputation: 667

Only way I can think of is to run your container with your script at the start; docker run -d --name my_container nginx /etc/init.d/myscript

Upvotes: 0

Related Questions