Ryan Sayer
Ryan Sayer

Reputation: 86

How to gracefully stop docker services with docker-compose down when EC2 stop-instances is issued

I have multiple Amazon Linux 2 boxes acting as Docker hosts, as the instances are needed Mon-Fri 9am-5pm, in an effort to save costs Shutdown tags that allow specific stop/start times have been implemented. I'm concerned that issuing stop-instances isn't gracefully shutting down the containers and may lead to volume corruption.

How can I make it so that when stop-instances is issued, the docker host is able to react and issue docker-compose down and then on instance startup issue docker-compose up -d?

Upvotes: 2

Views: 2622

Answers (1)

Neo Anderson
Neo Anderson

Reputation: 6340

When the stop-instances is issued, a graceful shutdown is triggered by the ACPI shutdown button press event from the hypervisor.

The OS has four minutes, before a hard shutdown is performed.

I have zero experience with Amazon Linux 2 but I assume that systemd handles the graceful shutdown of the system.

You can add run the docker-compose up/down in a start-up respectively shutdown-script.

Running a start-up script is already described in this post.
Running a shutdown-script is already described in this post.

Upvotes: 1

Related Questions