getSuggestedCommandForContainerLog returns a command that can be used to find out what is wrong with a container
(c *container.Summary, timeout int)
| 414 | |
| 415 | // getSuggestedCommandForContainerLog returns a command that can be used to find out what is wrong with a container |
| 416 | func getSuggestedCommandForContainerLog(c *container.Summary, timeout int) (string, string) { |
| 417 | var suggestedCommands []string |
| 418 | service := c.Labels["com.docker.compose.service"] |
| 419 | if service != "" && service != "ddev-router" && service != "ddev-ssh-agent" { |
| 420 | suggestedCommands = append(suggestedCommands, fmt.Sprintf("ddev logs -s %s", service)) |
| 421 | } |
| 422 | name := ContainerName(c) |
| 423 | suggestedCommands = append(suggestedCommands, fmt.Sprintf("docker logs %s", name), fmt.Sprintf("docker inspect --format \"{{ json .State.Health }}\" %s | docker run -i --rm ddev/ddev-utilities jq -r", name)) |
| 424 | troubleshootingCommand, _ := util.ArrayToReadableOutput(suggestedCommands) |
| 425 | suggestedCommand := "\nTroubleshoot this with these commands:\n" + troubleshootingCommand |
| 426 | if timeout > 0 && service != "ddev-router" && service != "ddev-ssh-agent" { |
| 427 | timeoutNote := "\nIf your internet connection is slow, consider increasing the timeout by running this:\n" |
| 428 | timeoutCommand, _ := util.ArrayToReadableOutput([]string{fmt.Sprintf("ddev config --default-container-timeout=%d && ddev restart", timeout*2)}) |
| 429 | suggestedCommand = suggestedCommand + timeoutNote + timeoutCommand |
| 430 | } |
| 431 | if globalconfig.DdevDebug { |
| 432 | ctx, apiClient, err := GetDockerClient() |
| 433 | if err == nil { |
| 434 | var stdout bytes.Buffer |
| 435 | logOpts := client.ContainerLogsOptions{ |
| 436 | ShowStdout: true, |
| 437 | ShowStderr: true, |
| 438 | Follow: false, |
| 439 | Timestamps: false, |
| 440 | } |
| 441 | rc, err := apiClient.ContainerLogs(ctx, c.ID, logOpts) |
| 442 | if err != nil { |
| 443 | util.Warning("Unable to capture logs from %s container: %v", name, err) |
| 444 | } else { |
| 445 | defer rc.Close() |
| 446 | _, err = stdcopy.StdCopy(&stdout, &stdout, rc) |
| 447 | if err != nil { |
| 448 | util.Warning("Unable to copy logs from %s container: %v", name, err) |
| 449 | } |
| 450 | util.Debug("Logs from failed %s container:\n%s\n", name, strings.TrimSpace(stdout.String())) |
| 451 | } |
| 452 | _, logOutput := GetContainerHealth(c) |
| 453 | util.Debug("Health log from failed %s container:\n%s\n", name, strings.TrimSpace(logOutput)) |
| 454 | } |
| 455 | } |
| 456 | return name, suggestedCommand |
| 457 | } |
| 458 | |
| 459 | // ContainerName returns the container's human-readable name. |
| 460 | func ContainerName(c *container.Summary) string { |
no test coverage detected