...

/

Starting and stopping services

Starting and stopping services

We will discuss the life cycle of containers and how Compose helps in stopping and starting particular services.

Life cycle of containers

A common thing we will need to do while developing our application is to stop or start the various services that make it up. In a moment, we will dive into the fine-grained control Compose gives us to do this. Before we do, though, it is helpful to have in mind the journey that containers go through from creation until they are no longer needed. The following figure shows a simplified version of a container’s life cycle:

Created state

A container comes into existence in the created state. It does not execute any code; it merely sits around waiting until it is called for. When the container is started, it moves into the running state, where it actively executes code. The docker run command we have seen creates a new container, then starts it running.

Running state

In the running state, a container can be restarted, stopped, killed, or paused. Pausing a ...