title: Docker container doesn't start, showing as 'Exited n seconds ago'
body: <p>I am trying to understand how docker works when it comes to starting / getting into a container. I am new to this so bear with me. I tried finding the answer to my need in SO but could not so far. </p>
  
  <p>I am trying to achieve 3 basic things:</p>
  
  <ul>
  <li>Start a container</li>
  <li>Make sure all ports are mapped to my container (i.e. I can see my container's apache from outside my container)</li>
  <li>SSH or get console into my container</li>
  </ul>
  
  <p>Here is what I am using to start a container:</p>
  
  <pre><code>caldav@caldav:~/docker/caldav-server$ sudo docker run -it -d -P  caldav-server service apache2 start
  </code></pre>
  
  <p>48fbea1865e302768a863767bf01b08f35f0221a4b29e5f2208d57e54660ef42</p>
  
  <p>But when I run ps, I see it as 'exited n seconds ago':</p>
  
  <pre><code>CONTAINER ID        IMAGE               COMMAND                CREATED             STATUS                     PORTS               NAMES
  48fbea1865e3        caldav-server       "service apache2 sta   2 seconds ago       Exited (0) 1 seconds ago 
  </code></pre>
  
  <p>What does this even mean? And obviously, I dont get to see it up and running when I go to <a href="http://[IP_ADDRESS]" rel="nofollow">http://[IP_ADDRESS]</a></p>
  
  <p>UPDATE: Ok, when I remove the apache start command it seems to stay up:</p>
  
  <pre><code>CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
  20d5daca6237        caldav-server       "/bin/bash"         10 seconds ago      Up 9 seconds                            thirsty_ritchie     
  </code></pre>
  
  <p>But then I dont seem to be able to get console into it. This is what I tried:</p>
  
  <pre><code>docker attach 20d5daca6237
  </code></pre>
  
  <p>Which is fine (gives me bash access). However, when I try to exit it by typing</p>
  
  <pre><code>$ exit
  </code></pre>
  
  <p>it then shows the container as the 'exited' status in ps. Am I doing it wrong?</p>