Is it possible to show the restart policy of a running Docker container?

前端 未结 4 2113
清歌不尽
清歌不尽 2021-02-04 23:50

When I create containers I\'m specifying a restart policy, but this is not shown in docker ps, and it doesn\'t appear any format string shows this either.

D

4条回答
  •  遇见更好的自我
    2021-02-05 00:20

    I did this little script to check all the containers and their policy:

    #!/usr/bin/env bash
    #Script to check the restart policy of the containers
    
    readarray -t CONTAINERS < <(docker ps -a | grep -v NAMES | awk '{print $NF}')
    
    for item in "${CONTAINERS[@]}"; do
    
        #Hard-Bash way
        #data=$(docker inspect "${item}" | grep -A 1 RestartPolicy | awk -F '"' '{print $4}' | tail -n 1)
    
        #Docker-pr0 way
        data=$(docker inspect -f "{{ .HostConfig.RestartPolicy.Name }}" "${item}")
    
        echo "Container: ${item} / RestartPolicy: ${data}"
    done
    

    Hope it helps to somebody!

提交回复
热议问题