Skip to content
This repository has been archived by the owner on Oct 13, 2023. It is now read-only.

[18.09 backport] Fix stopped containers with restart-policy showing as "restarting" #181

Conversation

thaJeztah
Copy link
Member

@thaJeztah thaJeztah commented Mar 26, 2019

backport of moby#38737 for 18.09
fixes moby#38720 for 18.09

When manually stopping a container with a restart-policy, the container
would show as "restarting" in docker ps whereas its actual state
is "exited".

Stopping a container with a restart policy shows the container as "restarting"

docker run -d --name test --restart unless-stopped busybox false

docker stop test

docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                       PORTS               NAMES
7e07409fa1d3        busybox             "false"             5 minutes ago       Restarting (1) 4 minutes ago                     test

However, inspecting the same container shows that it's exited:

docker inspect test --format '{{ json .State }}'
{
  "Status": "exited",
  "Running": false,
  "Paused": false,
  "Restarting": false,
  "OOMKilled": false,
  "Dead": false,
  "Pid": 0,
  "ExitCode": 1,
  "Error": "",
  "StartedAt": "2019-02-14T13:26:27.6091648Z",
  "FinishedAt": "2019-02-14T13:26:27.689427Z"
}

And killing the container confirms this;

docker kill test
Error response from daemon: Cannot kill container: test: Container 7e07409fa1d36dc8d8cb8f25cf12ee1168ad9040183b85fafa73ee2c1fcf9361 is not running

docker run -d --name test --restart unless-stopped busybox false

docker stop test

docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                PORTS               NAMES
d0595237054a        busybox             "false"             5 minutes ago       Restarting (1)       4 minutes ago                       exit

Signed-off-by: Sebastiaan van Stijn github@gone.nl
(cherry picked from commit 8c0ecb6)
Signed-off-by: Sebastiaan van Stijn github@gone.nl

- What I did

- How I did it

- How to verify it

- Description for the changelog

- A picture of a cute animal (not mandatory but encouraged)

When manually stopping a container with a restart-policy, the container
would show as "restarting" in `docker ps` whereas its actual state
is "exited".

Stopping a container with a restart policy shows the container as "restarting"

    docker run -d --name test --restart unless-stopped busybox false

    docker stop test

    docker ps
    CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                       PORTS               NAMES
    7e07409fa1d3        busybox             "false"             5 minutes ago       Restarting (1) 4 minutes ago                     test

However, inspecting the same container shows that it's exited:

    docker inspect test --format '{{ json .State }}'
    {
      "Status": "exited",
      "Running": false,
      "Paused": false,
      "Restarting": false,
      "OOMKilled": false,
      "Dead": false,
      "Pid": 0,
      "ExitCode": 1,
      "Error": "",
      "StartedAt": "2019-02-14T13:26:27.6091648Z",
      "FinishedAt": "2019-02-14T13:26:27.689427Z"
    }

And killing the container confirms this;

    docker kill test
    Error response from daemon: Cannot kill container: test: Container 7e07409fa1d36dc8d8cb8f25cf12ee1168ad9040183b85fafa73ee2c1fcf9361 is not running

    docker run -d --name test --restart unless-stopped busybox false

    docker stop test

    docker ps
    CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                PORTS               NAMES
    d0595237054a        busybox             "false"             5 minutes ago       Restarting (1)       4 minutes ago                       exit

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit 8c0ecb6)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
@thaJeztah thaJeztah added this to the 18.09.4 milestone Mar 26, 2019
@thaJeztah
Copy link
Member Author

@cpuguy83 @tonistiigi PTAL

@cpuguy83
Copy link

Lgtm

@thaJeztah thaJeztah modified the milestones: 18.09.4, 18.09.5 Mar 28, 2019
Copy link

@andrewhsu andrewhsu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

ignoring flakey test

FAIL: docker_api_swarm_test.go:297: DockerSwarmSuite.TestAPISwarmLeaderElection

@andrewhsu andrewhsu merged commit 160b62e into docker-archive:18.09 Mar 28, 2019
@thaJeztah thaJeztah deleted the 18.09_backport_fix_stopped_restart_containers branch March 28, 2019 16:11
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants