Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run command to docker container in a script

Tags:

docker

I need run command to docker container in a script, i trying with:

docker run -it <container> /bin/bash -c "command"

I had no error but the command is not executed

like image 664
hellb0y77 Avatar asked Jan 30 '15 15:01

hellb0y77


People also ask

How do I run a docker container command?

To use the docker exec command, you will need a running Docker container. If you don't already have a container, start a test container with the following docker run command: docker run -d --name container-name alpine watch "date >> /var/log/date. log"

How do I execute a docker container as a root?

Docker containers are designed to be accessed as root users to execute commands that non-root users can't execute. We can run a command in a running container using the docker exec. We'll use the -i and -t option of the docker exec command to get the interactive shell with TTY terminal access.


1 Answers

I can not create a new image, i must not stop the service ... I do it manually

It's possible to invoke a command in a running container:

docker exec <container_id> rm -f /tmp/cache/*/*/*
like image 143
lifus Avatar answered Oct 20 '22 00:10

lifus