6

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

6
  • 1
    Could you be more specific? e.g. docker run -it <container> /bin/bash -c "echo 'Hello'" works fine. <container> is centos in my case Commented Jan 30, 2015 at 15:26
  • I need clear cache on nginx container, i run: docker run -it nginx /bin/bash -c "rm -f /tmp/cache/*/*/*". If i launch this command inside container it work, in this way the cache is not cleared Commented Jan 30, 2015 at 16:17
  • that's because you should commit you change Commented Jan 30, 2015 at 16:19
  • no, docker commit nginx successful, but the files are still there Commented Jan 30, 2015 at 16:32
  • I can not create a new image, i must not stop the service ... I do it manually Commented Jan 30, 2015 at 16:40

1 Answer 1

3

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/*/*/*
Sign up to request clarification or add additional context in comments.

6 Comments

I have alredy trying, i not get any error but the files were not deleted
@user2385354 Are you sure that rm -f /tmp/cache/*/*/* is what you actually need? Are you going to remove /tmp/cache and all its subfolders? If so, then rm -rf /tmp/cache is what you need
If i launch rm -rf it erase all folder and nginx stop working, i need stop and start container, instead rm -f erase only file in all folder and suibfolder.
You may remove all files as follows find /tmp/cache/ -type f -delete. You may also add -maxdepth <n> if you want.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.