>_ IzzyLab

Hands-on task

This task is step 4 of the course “Docker from scratch”

Stop, start, restart

easy~5 min

There are three containers on the server: web, cache and worker. Do the following:

  • stop cache without removing it;
  • worker is stopped right now — start it again;
  • restart web.

Don't recreate the containers: it has to be these exact ones.

What you'll practise:
  • docker stop
  • docker start
  • docker restart

Topic breakdown

You can stop and start a container as many times as you like — it's the same container with the same ID, name, settings and files.

  • docker stop name sends the main process a SIGTERM signal and waits for it to exit. If it doesn't finish within 10 seconds, Docker finishes it off with SIGKILL. -t changes the timeout.
  • docker start name starts a stopped container again — with the same command and flags it was created with.
  • docker restart name is stop and start in a row, for example to make a service reread its settings.
docker stop timer && docker start timer

docker run, on the other hand, creates a new container every time. If you run it with the name of an existing container, Docker refuses: the name is taken.

What's checked

  1. cache is stopped (the same container)
  2. worker is running again (the same container)
  3. web was restarted and is running (the same container)

What it looks like