title: How can I reuse a Docker container as a service?
body: <p>I already have a running container for both postgres and redis in use for various things. However, I started those from the command line months ago. Now I'm trying to install a new application and the recipe for this involves writing out a docker compose file which includes both postgres and redis as services.</p>
  
  <p>Can the compose file be modified in such a way as to specify the already-running containers? Postgres already does a fine job of siloing any of the data, and I can't imagine that it would be a problem to reuse the running redis.</p>
  
  <p>Should I even reuse them? It occurs to me that I could run multiple containers for both, and I'm not sure there would be any disadvantage to that (other than a cluttered docker ps output).</p>
  
  <p>When I set container_name to the names of the existing containers, I get what I assume is a rather typical error of:</p>
  
  <pre><code>cb7cb3e78dc50b527f71b71b7842e1a1c". You have to remove (or rename) that container to be able to reuse that name.
  </code></pre>
  
  <p>Followed by a few that compain that the ports are already in use (5432, 6579, etc).</p>
  
  <p>Other answers here on Stackoverflow suggest that if I had originally invoked these services from another compose file with the exact same details, I could do so here as well and it would reuse them. But the command I used to start them was somehow never written to my bash_history, so I'm not even sure of the details (other than name, ports, and restart always). </p>