-
Notifications
You must be signed in to change notification settings - Fork 5.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Stream logs during --wait
#9122
Comments
Or some additional flag like |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
:-( |
This issue has been automatically closed because it had not recent activity during the stale period. |
Should be re-opened |
Yes, please! |
Out of curiosity, I built a simple Bash script that accomplishes the task at some sort: #!/usr/bin/env bash
set -euo pipefail
container_name="${1}"
max_attempts="${2:-120}"
# Display logs while we wait for the container to be healthy
docker logs --follow "${container_name}" &
docker_logs_pid="${!}"
function cleanup() {
# do not fail if the process has already exited
kill "${docker_logs_pid}" 2>/dev/null || true
}
# Cleanup log process on exit
trap 'cleanup' EXIT
# Wait for container to be healthy
attempt=0
while true; do
status=$(docker inspect --format '{{.State.Health.Status}}' "${container_name}" || true)
if [[ "${status}" == "healthy" ]]; then
cleanup
echo "Container ${container_name} is healthy after ${attempt} seconds"
exit 0
elif [[ "${status}" != "starting" ]]; then
attempt=$(( attempt + 1 ))
if [[ "${attempt}" -ge "${max_attempts}" ]]; then
cleanup
echo "Container ${container_name} is not healthy after ${attempt} seconds"
echo "Last healthcheck logs:"
docker inspect --format '{{json .State.Health}}' "${container_name}"
exit 1
fi
fi
sleep 1
done It has proven to be extremely helpful for debugging issues during CI pipelines. And it would be even better if docker-compose have built-in support for it. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Please don't let this stall :) |
This issue has been automatically marked as not stale anymore due to the recent activity. |
The challenge here is that we can't dump logs to the console while rendering the "progress" UI showing resource status. |
@ndeloof, perhaps some inspiration can be taken from the way how |
@ndeloof AFTER the Could be an easier first step and help troubleshoot most cases. |
The addition of
--wait
(#8777) was nice. But it would be especially helpful in CI/CD environments if the logs were streamed during the "wait".For example, I'm trying to start an Oracle DB with
--wait
and it's not working. On CI/CD it's almost impossible to capture the logs for it unless I do some very weird trickery of runningdocker compose logs -f
in parallel.I understand that
--wait
implies--detach
, but I guess it does not need to be the case until the--wait
condition is met.The text was updated successfully, but these errors were encountered: