How to execute shall script or other script or command in running container

Hello

I have multiple containers in my private network.

I want to execute command like in running container without enter in it.

Like i want to some bash file in my main host and i want to execute in my running container same i also want to execute command in my running container.

Please suggest me

Hey Thanks !!

It’s working but when I execute from jenkins it gives below error.

[SSH] executing…
the input device is not a TTY

[SSH] completed
[SSH] exit-status: 1

Build step ‘Execute shell script on remote host using ssh’ marked build as failure
Finished: FAILURE

Jenkins does not execute jobs in a tty. So when you exec into your container, do not do “-t”

For jenkins and docker, this is probably the way to go:

Yes I have tried without -t and it’s working.
Thanks for the support.

You can also try with below mentioned command

docker exec -i container-id sh -c ‘cd /var/www/html/wordpress && git pull’

Above command execute pull in to container.

2 Likes