Add destroy_grace_seconds option to stop container before delete (#7513)

This commit is contained in:
JB Arsenault 2016-07-11 11:03:02 -04:00 committed by Paul Stack
parent 6154fad933
commit 439a19426c
3 changed files with 14 additions and 0 deletions

View file

@ -285,6 +285,11 @@ func resourceDockerContainer() *schema.Resource {
ForceNew: true,
},
"destroy_grace_seconds": &schema.Schema{
Type: schema.TypeInt,
Optional: true,
},
"labels": &schema.Schema{
Type: schema.TypeMap,
Optional: true,

View file

@ -265,6 +265,14 @@ func resourceDockerContainerUpdate(d *schema.ResourceData, meta interface{}) err
func resourceDockerContainerDelete(d *schema.ResourceData, meta interface{}) error {
client := meta.(*dc.Client)
// Stop the container before removing if destroy_grace_seconds is defined
if d.Get("destroy_grace_seconds").(int) > 0 {
var timeout = uint(d.Get("destroy_grace_seconds").(int))
if err := client.StopContainer(d.Id(), timeout); err != nil {
return fmt.Errorf("Error stopping container %s: %s", d.Id(), err)
}
}
removeOpts := dc.RemoveContainerOptions{
ID: d.Id(),
RemoveVolumes: true,

View file

@ -255,6 +255,7 @@ resource "docker_container" "foo" {
entrypoint = ["/bin/bash", "-c", "ping localhost"]
user = "root:root"
restart = "on-failure"
destroy_grace_seconds = 10
max_retry_count = 5
memory = 512
memory_swap = 2048