Answers: <p>There are 2 really major points for Docker containers. </p>
  
  <ol>
  <li>You make sure the app dependencies are versioned and encapsulated
  inside the container. Container runs smoothly eveywhere, as long as you have the Docker daemon.</li>
  <li>You have the capability to create/destroy a
  container on any time, also known as ephemeral property. You could test easily, maintain N of them if needed ( Replica Sets in K8S for example are doing just that, Docker Swarm uses services to maintain this number as well ).</li>
  </ol>
  
  <p>The official Docker docs defines an image as</p>
  
  <blockquote>
    <p>An image is a read-only template with instructions for creating a
    Docker container</p>
  </blockquote>
  
  <p>You can't remove an image, because the container relies on it. </p>
  
  <pre><code>docker image rm ubuntu:20.04
  Error response from daemon: conflict: unable to remove repository reference "ubuntu:20.04" (must force) - container ecd06b4eb4bf is using its referenced image
  </code></pre>
  
  <p>Then you might force the process</p>
  
  <pre><code> docker image rm -f ubuntu:20.04
  Untagged: ubuntu:20.04
  Untagged: ubuntu@sha256:747d2dbbaaee995098c9792d99bd333c6783ce56150d1b11e333bbceed5c54d7
  Untagged: ubuntu@sha256:8bce67040cd0ae39e0beb55bcb976a824d9966d2ac8d2e4bf6119b45505cee64
  </code></pre>
  
  <p>But that just untags the image, it's still here.</p>
  
  <pre><code>docker image ls
  REPOSITORY             TAG                                        IMAGE ID            CREATED             SIZE
  &lt;none&gt;                 &lt;none&gt;                                     1d622ef86b13        3 weeks ago         73.9MB
  </code></pre>
  
  <p>So to your question, the best practice is to only remove images that are not being used by any containers. If you maintain 2-5 versions of your app, you could safely remove the others. Also you schould strive for minimum size of each image, even in total that schould not bother your available space that much. </p>
  
Answers: CC BY-SA 4.0
Answers: 2020-05-17T19:44:41.360Z
Answers: 2020-05-17T19:44:41.360Z
Answers: Recoba20
Body: <p>Trying to save space on the server, and I've noticed that the running containers are much smaller in size than the images I've had to pull to create the containers.</p>
  
  <p>I was wondering about the dependency of the running containers on the images  and  if it it's possible to remove the images and only keep the containers.</p>
  
Tags: <docker>
Title: Can I remove a docker image and still keep the container?
UserDisplayName: Tlink
ThreadText: # Can I remove a docker image and still keep the container?
  
  (Asked by: username_0 on 2020-05-16)
  
  Trying to save space on the server, and I've noticed that the running containers are much smaller in size than the images I've had to pull to create the containers.
  
  I was wondering about the dependency of the running containers on the images and if it it's possible to remove the images and only keep the containers.
  
  **Tags:** docker
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2020-05-17. Score: 8 | Accepted answer
  
  There are 2 really major points for Docker containers.
  
  1. You make sure the app dependencies are versioned and encapsulated
     inside the container. Container runs smoothly eveywhere, as long as you have the Docker daemon.
  2. You have the capability to create/destroy a
     container on any time, also known as ephemeral property. You could test easily, maintain N of them if needed ( Replica Sets in K8S for example are doing just that, Docker Swarm uses services to maintain this number as well ).
  
  The official Docker docs defines an image as
  
  > An image is a read-only template with instructions for creating a
  > Docker container
  
  You can't remove an image, because the container relies on it.
  
  ```
  docker image rm ubuntu:20.04
  Error response from daemon: conflict: unable to remove repository reference "ubuntu:20.04" (must force) - container ecd06b4eb4bf is using its referenced image
  
  ```
  
  Then you might force the process
  
  ```
   docker image rm -f ubuntu:20.04
  Untagged: ubuntu:20.04
  Untagged: ubuntu@sha256:747d2dbbaaee995098c9792d99bd333c6783ce56150d1b11e333bbceed5c54d7
  Untagged: ubuntu@sha256:8bce67040cd0ae39e0beb55bcb976a824d9966d2ac8d2e4bf6119b45505cee64
  
  ```
  
  But that just untags the image, it's still here.
  
  ```
  docker image ls
  REPOSITORY             TAG                                        IMAGE ID            CREATED             SIZE
  <none>                 <none>                                     1d622ef86b13        3 weeks ago         73.9MB
  
  ```
  
  So to your question, the best practice is to only remove images that are not being used by any containers. If you maintain 2-5 versions of your app, you could safely remove the others. Also you schould strive for minimum size of each image, even in total that schould not bother your available space that much.
  
  
  ---
  
  