<p>Option <code>--rm</code> tells Docker explicitly to remove the container after the (main) command finished. Just leave it out.</p>

<p>Note that none of <a href="https://github.com/anshumanbh/git-all-secrets#scanning-an-organization-team" rel="nofollow noreferrer">the examples</a> contain this option; they only use it for <code>-help</code>.</p>

<p>As an alternative (which lets you keep <code>--rm</code>), you can tell Docker to <a href="https://docs.docker.com/storage/volumes/" rel="nofollow noreferrer">mount a volume</a> at <code>/root</code>. Volumes persist after the containers mounting them go away, so you can access the data written there. However, for your purposes here, a simple <a href="https://docs.docker.com/storage/bind-mounts/" rel="nofollow noreferrer">bind mount</a> is quite enough; add</p>

<pre><code>-v .:/root
</code></pre>

<p>to have it write the output file to the current (host) directory. You may have to adjust this if <code>/root</code> is used heavily; you probably want to use a previously empty directory on both sides.</p>

CC BY-SA 4.0
2019-02-21T15:27:56.347Z
2019-02-21T19:14:06.690Z
2019-02-21T19:14:06.690Z
Raphael
<p>I don't know about <code>git-all-secret</code> specifically, but from what I understand you are trying to capture the output produced by that tool. Since docker maps by default the standard output of a container to the standard output of the client <code>docker</code> command, you may achieve the desired result using something like that (untested):</p>

<pre><code>sudo docker run --rm -it abhartiya/tools_gitallsecrets -org $org \
     -output /dev/stdout \
     -thogEntropy -token $githubtoken \
 &gt; ./output.txt
</code></pre>

<p>Many tools allow <code>-</code> as a synonym for /dev/stdout, so this might work:</p>

<pre><code>sudo docker run --rm -it abhartiya/tools_gitallsecrets -org $org \
     -output - \
     -thogEntropy -token $githubtoken \
 &gt; ./output.txt
</code></pre>

CC BY-SA 4.0
2019-02-25T11:26:53.483Z
2019-02-25T11:26:53.483Z
Sylvain Leroux
<p>Docker container dies when there is no process run in it. If you want a docker not to die you need a process to keep runing, This can be any process even bash process (/bin/bash). </p>

<p>Usually a docker container can be re-started with <code>docker start</code> command, but you are using the <code>--rm</code> flag which tell the docker deamon to delete the container once it killed, meaning that when the container is stoped auto delete it, therefor you cannot re-start the container. </p>

<p>Your problem is that you are using the docker in a wrong way, you tell the docker container to write the output of the process to the docker container file system and then delete the container, then you try to copy it. </p>

<p>You should use a mounted volume from your host (by using <code>-v</code> flag) and write the output there, or you can enter docker with runing the command <code>/bin/bash</code> at the end, then you can run the process manually from inside the docker container, wait for it to finished, press <code>ctrl+p+q</code> to exit the container without killing it and copy the file using <code>docker cp</code> command and then kill the container what ever make you. Note that because <code>/bin/bash</code>  the container has a process and therefor it will not be killed (as your question was "how to stop from container from dying...").</p>

CC BY-SA 4.0
2019-02-24T14:04:24.580Z
2019-02-24T14:04:24.580Z
milki
<p>I'm running <a href="https://github.com/anshumanbh/git-all-secrets" rel="nofollow noreferrer">git-all-secrets</a> over our organisation to ensure we have nothing exposed. I'm doing this using:</p>

<pre><code>sudo docker run --rm -it abhartiya/tools_gitallsecrets -org &lt;org&gt; -output /root/output.txt -thogEntropy -token &lt;githubtoken&gt;
</code></pre>

<p>I've monitored the events for this repository, and after the command completes, the following events fire:</p>

<pre><code>2019-02-21T13:01:36.386539368Z container die cc479e7ac878f39c1e555eea1cbc9105dc06e21a526639975cd15f031297ab23 (exitCode=0, image=abhartiya/tools_gitallsecrets, name=inspiring_bell)
2019-02-21T13:01:36.602243215Z network disconnect 26b5a225be28b13153e587c4d1464361957ac899bc1a4152c6ae5aacc3229a0f (container=cc479e7ac878f39c1e555eea1cbc9105dc06e21a526639975cd15f031297ab23, name=bridge, type=bridge)
2019-02-21T13:01:37.235130059Z container destroy cc479e7ac878f39c1e555eea1cbc9105dc06e21a526639975cd15f031297ab23 (image=abhartiya/tools_gitallsecrets, name=inspiring_bell)
</code></pre>

<p>Since the container is  then destroyed, I can't then copy the file locally after exection by using:</p>

<pre><code>a@ubuntu-s-2v-2-01:~$ sudo docker cp cc479e7ac878:/root/output.txt ./output.txt                                                                                                                     │ 0 -rw-r--r-- 1 codingo codingo     0 Dec 19 04:49 .sudo_as_admin_successful
Error: No such container:path: cc479e7ac878:/root/output.txt                         
</code></pre>

<p>I'm still new to docker, so I'm not sure what the solution to my problem is - but how can I have  the docker contain</p>

<docker><containers>
How to stop a container dying at the end of an execution?
Michael A
# How to stop a container dying at the end of an execution?

(Asked by: username_0 on 2019-02-21)

I'm running git-all-secrets over our organisation to ensure we have nothing exposed. I'm doing this using:
sudo docker run --rm -it abhartiya/tools_gitallsecrets -org  -output /root/output.txt -thogEntropy -token 

I've monitored the events for this repository, and after the command completes, the following events fire:
2019-02-21T13:01:36.386539368Z container die cc479e7ac878f39c1e555eea1cbc9105dc06e21a526639975cd15f031297ab23 (exitCode=0, image=abhartiya/tools_gitallsecrets, name=inspiring_bell)
2019-02-21T13:01:36.602243215Z network disconnect 26b5a225be28b13153e587c4d1464361957ac899bc1a4152c6ae5aacc3229a0f (container=cc479e7ac878f39c1e555eea1cbc9105dc06e21a526639975cd15f031297ab23, name=bridge, type=bridge)
2019-02-21T13:01:37.235130059Z container destroy cc479e7ac878f39c1e555eea1cbc9105dc06e21a526639975cd15f031297ab23 (image=abhartiya/tools_gitallsecrets, name=inspiring_bell)

Since the container is  then destroyed, I can't then copy the file locally after exection by using:
a@ubuntu-s-2v-2-01:~$ sudo docker cp cc479e7ac878:/root/output.txt ./output.txt                                                                                                                     │ 0 -rw-r--r-- 1 codingo codingo     0 Dec 19 04:49 .sudo_as_admin_successful
Error: No such container:path: cc479e7ac878:/root/output.txt                         

I'm still new to docker, so I'm not sure what the solution to my problem is - but how can I have  the docker contain

**Tags:** docker, containers


---

## 3 answers

### Answer by username_1 on 2019-02-21. Score: 3 | Accepted answer

Option --rm tells Docker explicitly to remove the container after the (main) command finished. Just leave it out.
Note that none of the examples contain this option; they only use it for -help.
As an alternative (which lets you keep --rm), you can tell Docker to mount a volume at /root. Volumes persist after the containers mounting them go away, so you can access the data written there. However, for your purposes here, a simple bind mount is quite enough; add
-v .:/root

to have it write the output file to the current (host) directory. You may have to adjust this if /root is used heavily; you probably want to use a previously empty directory on both sides.


---

### Answer by username_2 on 2019-02-25. Score: 0

I don't know about git-all-secret specifically, but from what I understand you are trying to capture the output produced by that tool. Since docker maps by default the standard output of a container to the standard output of the client docker command, you may achieve the desired result using something like that (untested):
sudo docker run --rm -it abhartiya/tools_gitallsecrets -org $org \
     -output /dev/stdout \
     -thogEntropy -token $githubtoken \
 > ./output.txt

Many tools allow - as a synonym for /dev/stdout, so this might work:
sudo docker run --rm -it abhartiya/tools_gitallsecrets -org $org \
     -output - \
     -thogEntropy -token $githubtoken \
 > ./output.txt


---

### Answer by username_3 on 2019-02-24. Score: 0

Docker container dies when there is no process run in it. If you want a docker not to die you need a process to keep runing, This can be any process even bash process (/bin/bash).

Usually a docker container can be re-started with `docker start` command, but you are using the `--rm` flag which tell the docker deamon to delete the container once it killed, meaning that when the container is stoped auto delete it, therefor you cannot re-start the container.

Your problem is that you are using the docker in a wrong way, you tell the docker container to write the output of the process to the docker container file system and then delete the container, then you try to copy it.

You should use a mounted volume from your host (by using `-v` flag) and write the output there, or you can enter docker with runing the command `/bin/bash` at the end, then you can run the process manually from inside the docker container, wait for it to finished, press `ctrl+p+q` to exit the container without killing it and copy the file using `docker cp` command and then kill the container what ever make you. Note that because `/bin/bash` the container has a process and therefor it will not be killed (as your question was "how to stop from container from dying...").


---

