title: how to remove non existent docker image
body: <p>I am trying to run repair command for mongod, but daemon gave conflict error, so i removed the container and again run the repair command and daemon gave again same conflict error, this time i removed container with the container id displayed in the error and daemon says "no such id". </p>
  
  <p>So, can anyone let me know that how can i remove this container so that i can successfully run the repair command.</p>
  
  <p>I am displaying my docker commands as below for reference</p>
  
  <h2>Below is my docker ps result</h2>
  
  <pre><code>root@ip-172-31-6-252:~# docker ps
  CONTAINER ID        IMAGE                         COMMAND                CREATED             STATUS              PORTS                                        
  
            NAMES
  1f7bdd83dac0        mongo:latest                  "/entrypoint.sh mong   23 hours ago        Up 23 hours         27017/tcp                                    
  
            cpx.db
  11e2123f7e2a        centralpx/cpx.server:latest   "/run.sh"              2 weeks ago         Up 2 weeks          0.0.0.0:80-&gt;80/tcp                           
  
            cpx.server.live
  4008c7772f63        centralpx/cpx-ftp             "/bin/sh -c '/usr/sb   7 months ago        Up 4 months         0.0.0.0:21-&gt;21/tcp, 0.0.0.0:30000-30009-&gt;30000-30009/tcp   cpx.ftp
  </code></pre>
  
  <h2>Below is my docker images result</h2>
  
  <pre><code>root@ip-172-31-6-252:~# docker images
  REPOSITORY             TAG                 IMAGE ID               CREATED             VIRTUAL SIZE
  mongo                  latest              21e69f355287        8 days ago          366.4 MB
  centralpx/cpx.server   latest              894a3c5fce73        2 weeks ago         429 MB
  centralpx/cpx-ftp      latest              e35ba5efa239        9 months ago        425.5 MB
  </code></pre>
  
  <h2>Now i get attached to cpx.db container and run shutdown command (i need to shutdown before running repair command)</h2>
  
  <pre><code>root@ip-172-31-6-252:~# docker exec -it cpx.db /bin/bash
  root@1f7bdd83dac0:/# mongod --shutdown
  killing process with pid: 1
  FATA[0026] Error response from daemon: Container    1f7bdd83dac037293d5086e86a3df7117b4b6eb2a3478d65848643eff9c4d568 is not running: Exited (0) Less than a second ago
  root@ip-172-31-6-252:~#
  </code></pre>
  
  <h2>Now below is my repair command</h2>
  
  <pre><code>root@ip-172-31-6-252:~# sudo docker run -it -p 28001:27017 --name cpx.db mongo:latest mongod --dbpath /data/db --repair
  FATA[0000] Error response from daemon: Conflict. The name "cpx.db" is already in use by container 8b2a8c98971c. You have to delete (or rename) that container to be able to reuse that name.
  </code></pre>
  
  <p>The above command gives conflict error, so we removed the container "cpx.db", below is the docker commands</p>
  
  <pre><code>root@ip-172-31-6-252:~# docker ps -a
  CONTAINER ID        IMAGE                         COMMAND                CREATED             STATUS                     PORTS                                                      NAMES
  1f7bdd83dac0        mongo:latest                  "/entrypoint.sh mong   23 hours ago        Exited (0) 3 minutes ago                                                              cpx.db
  11e2123f7e2a        centralpx/cpx.server:latest   "/run.sh"              2 weeks ago         Up 2 weeks                 0.0.0.0:80-&gt;80/tcp                                         cpx.server.live
  4008c7772f63        centralpx/cpx-ftp             "/bin/sh -c '/usr/sb   7 months ago        Up 4 months                0.0.0.0:21-&gt;21/tcp, 0.0.0.0:30000-30009-&gt;30000-30009/tcp   cpx.ftp
  
  
  
  root@ip-172-31-6-252:~# docker rm cpx.db
  cpx.db
  
  root@ip-172-31-6-252:~# docker ps -a
  CONTAINER ID        IMAGE                         COMMAND                CREATED             STATUS              PORTS                                                      NAMES
  11e2123f7e2a        centralpx/cpx.server:latest   "/run.sh"              2 weeks ago         Up 2 weeks          0.0.0.0:80-&gt;80/tcp                                         cpx.server.live
  4008c7772f63        centralpx/cpx-ftp             "/bin/sh -c '/usr/sb   7 months ago        Up 4 months         0.0.0.0:21-&gt;21/tcp, 0.0.0.0:30000-30009-&gt;30000-30009/tcp   cpx.ftp
  </code></pre>
  
  <p>Then we again run repair command as the conflicting container is removed and below is our command and output</p>
  
  <pre><code>root@ip-172-31-6-252:~# sudo docker run -it -p 28001:27017 --name cpx.db mongo:latest mongod --dbpath /data/db --repair
  FATA[0000] Error response from daemon: Conflict. The name "cpx.db" is already in use by container 8b2a8c98971c. You have to delete (or rename) that container to be able to reuse that name.
  </code></pre>
  
  <p>Daemon again gave conflict error</p>
  
  <p>We again removed the container with id shown in conflict message as below, and it shows no such id. Please refer below</p>
  
  <pre><code>root@ip-172-31-6-252:~# docker rm 8b2a8c98971c
  Error response from daemon: no such id: 8b2a8c98971c
  FATA[0000] Error: failed to remove one or more containers
  </code></pre>
  
  <p>So, can any one help us to remove this container which doesn't exists or can anyone help us to get rid of this issue.</p>
  
  <p>As you pointed the problem in command of instantiating the stopped container so i tried to correct my mistake in the command and run this command </p>
  
  <pre><code>sudo docker mongod --dbpath /data/db --repair
  </code></pre>
  
  <p>this command gives error </p>
  
  <pre><code>docker: 'mongod' is not a docker command. See 'docker --help'
  </code></pre>
  
  <p>and if i remove docker from command and run this command </p>
  
  <pre><code>sudo mongod --dbpath /data/db --repair
  </code></pre>
  
  <p>then it gives error </p>
  
  <pre><code>sudo: mongod: command not found
  </code></pre>
  
  <p>Can i ask that if my below command is wrong as i am using the stopped container</p>
  
  <pre><code>root@ip-172-31-6-252:~# sudo docker run -it -p 28001:27017 --name cpx.db mongo:latest mongod --dbpath /data/db --repair
  </code></pre>
  
  <p>Then if i removed the container and running this command then why this command is not executing and giving conflict error?</p>
  
  <p>EDIT:
  Based on recent reply and explanation i had updated my command as below just check it and let me know if there is any correction from your side</p>
  
  <pre><code>sudo docker run -it -p 28000:27017 --name cpx.db1 -v /home/ubuntu/data/cpx.db:/data/db -d mongo:latest mongod --dbpath /data/db --repair
  </code></pre>
  
  <p>My new process will be as below:
  1) go to the running container and stop the mongodb and this will automatically stop the running container
  2) run the updated repair command as below</p>
  
  <pre><code>sudo docker run -it -p 28000:27017 --name cpx.db1 -v /home/ubuntu/data/cpx.db:/data/db -d mongo:latest mongod --dbpath /data/db --repair
  </code></pre>
  
  <p>This command will create a new container named as "cpx.db1" and it will use volume to mount the db and run repair command</p>
  
  <p>3) I'll remove this new container "cpx.db1" as i want to use the old one.</p>
  
  <p>Let me know if i am wrong</p>
  
  <p>Thanks a lot in advance.</p>
  
  <p>Thanks </p>
  
  <p>EDIT:
  I run the command and i think it worked as it doesn't give any error but it executed very fast so i am confused, i am hereby stating my commands and output for your reference</p>
  
  <p>I entered in db container</p>
  
  <pre><code> docker exec -it cpx.db /bin/bash
  </code></pre>
  
  <p>I run shutdown command for mongodb</p>
  
  <pre><code> mongod --shutdown
  </code></pre>
  
  <p>This was the output (as only process was running in container so after killing this one process i was out of the container)</p>
  
  <pre><code>killing process with pid: 1
  FATA[0015] Error response from daemon: Container bd910137a3957c79b304dbbbd221317c909e6779de01ed6f780857e3914c577c is not running: Exited (0) Less than a second ago
  </code></pre>
  
  <p>Then i run the repair command as below</p>
  
  <pre><code> sudo docker run -it -p 28000:27017 --name cpx.db1 -v /home/ubuntu/data/cpx.db:/data/db -d mongo:latest mongod --dbpath /data/db --repair
  </code></pre>
  
  <p>This was the output</p>
  
  <pre><code>d6b61222c7145f178e95974c87f95cb06fc8aa5c0c1adc929050ca172ab5f73f
  </code></pre>
  
  <p>Then i start the old container</p>
  
  <pre><code>docker start cpx.db
  </code></pre>
  
  <p>And db get started</p>
  
  <p>There was no error but i am confused that whether repair command run successfully or not? Can you check my edited post and let me know your views .</p>