Killing a Docker Container

As I mentioned, I starting to learn and use Docker. Therefor I followed a nice YouTube tutorial which really gave me a kickstart. However, it seems that the way to terminate a docker container has either changed or was described wrong in this video. So I learned myself by checking what the docker function in PowerShell can do.

I tried terminating Docker Containers by simply pressing CTRL-C. I thought I’m done with that but no, I was not. That simply terminates the docker command process but not the container. I realized that when I wanted to start the same container right after I thought I terminated it. But an error (“docker bind failed port is already allocated”) popped up. So I checked Kitematic to find that the container still showed up running. (Also, going to localhost:80 still returned the webpage after “terminating” the container which seemed odd…)

So, simply CTRL-C did not do the trick. But thankfully there is docker stop and docker kill. But those commands need the (thankfully) human readable docker names. Unfortunately, docker run does not show you the name of the docker container it just started. However, docker ps does.

Here’s my current workflow:

  1. docker run -p 80:80 -v host:container buildname
  2. ctrl+c
  3. do whatever I do (coding, testing,…)
  4. docker ps and find out the name of my container
  5. docker stop containername

Is it the easiest? I don’t know. Is it the best? I don’t know. But maybe you know a simpler, better, smarter solution! I’d be happy to hear about it in the comments!


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s