Image

Use a Detached Container

Running a container interactively can be useful, but often it's not what we really need. A web server stack is made up of several components such as the Linux OS, the Apache web server, a PHP runtime, and a database such as MySQL. Collectively, we call this a LAMP stack. If we were to run these in Docker with what we now know, we'd have to keep open several terminal windows!

Obviously that's not what we want to do. Instead, we want to run the containers in the background. That way, we can use them like we would any web server. Fortunately, Docker makes running and managing a container in the a background easy with just a few commands.

In this tutorial, we'll:

  • Start a container in the background
  • Use docker ps to list running Docker containers
  • Use docker run to enter a container running in the background
  • Use docker kill to stop a container running in the background