Common Docker Container Status Codes and Their Meanings:

  • Created: The container has been created and prepared, but its main process has not yet been started. This state typically occurs after a docker create command.
  • Running: The container’s main process is actively executing. This is the desired state for an operational container.
  • Paused: The container’s processes are temporarily suspended, but the container itself is not terminated. This usually results from a docker pause command.
  • Exited: The container’s main process has completed its execution and terminated. This can happen if the process finished successfully (exit code 0) or due to an error (non-zero exit code).
  • Restarting: The container is in the process of restarting, often due to a configured restart policy or a manual restart command.
  • Removing: The container is in the process of being removed from the Docker host.
  • Dead: The container is in a defunct state and cannot be restarted or operated. This typically occurs in scenarios where a container was only partially removed or encountered a severe unrecoverable error. Dead containers can only be removed.
#!/bin/bash

echo "šŸ” Detecting container dependencies based on network and volume usage..."

# List all running containers
containers=$(docker ps -q -a)

for container in $containers; do
    echo "  -------------------------------------------------------------"
    cname=$(docker inspect --format '{{.Name}}' "$container" | sed 's/^\/\+//')
    #echo -e "  šŸ“¦ Container: $cname"
    status=$(docker inspect --format '{{.State.Status}}' "$container")
    #echo "  STATUS:$status"
    status_icon=āœ…
    if [ "$status" == "running" ]; then
        status_icon=āœ…
    else
        status_icon=āŒ
    fi
    # Get Mounts Source
    sources=$(docker inspect --format '{{range .Mounts}}{{.Source}} {{end}}' "$container")
    for source in $sources; do
        echo -e "  $status_icon šŸ“¦ $cname --Source: $source"
    done
    # Get Mounts volumes
    volumes=$(docker inspect --format '{{range .Mounts}}{{.Name}} {{end}}' "$container")
    for volume in $volumes; do
        echo "  $status_icon šŸ—‚  $cname --Volume: ${volume:-None}"
    done
    # Get networks
    networks=$(docker inspect --format '{{range $key, $value := .NetworkSettings.Networks}}{{$key}} {{end}}' "$container")
    echo "  $status_icon šŸ”— $cname --Networks: $networks"

    # Get linked containers (legacy linking)
    links=$(docker inspect --format '{{range .HostConfig.Links}}{{.}} {{end}}' "$container")
    echo "  $status_icon šŸ”— $cname --Links: ${links:-None}"
done

echo -e "\nāœ… Dependency scan complete."

Leave a Reply