enter: check for container errors during first start, Fix #242

This commit is contained in:
89luca89
2022-04-25 12:28:43 +02:00
parent 458eeb22d1
commit 4c1556fc15
+15 -4
View File
@@ -276,7 +276,7 @@ generate_command() {
done
# Start with the $PATH set in the container's config
container_paths="${container_PATH:-""}"
container_paths="${container_path:-""}"
# Ensure the standard FHS program paths are in PATH environment
standard_paths="/usr/local/sbin /usr/local/bin /usr/sbin /usr/bin /sbin /bin"
# add to the PATH after the existing paths, and only if not already present
@@ -342,11 +342,11 @@ if [ "${dryrun}" -ne 0 ]; then
fi
# Inspect the container we're working with.
container_status=unknown
container_PATH="${PATH}"
container_status="unknown"
container_path="${PATH}"
eval "$(${container_manager} inspect --type container "${container_name}" --format \
'container_status={{.State.Status}};
{{range .Config.Env}}{{if slice . 0 5 | eq "PATH="}}container_PATH={{slice . 5 | printf "%q"}}{{end}}{{end}}')"
{{range .Config.Env}}{{if slice . 0 5 | eq "PATH="}}container_path={{slice . 5 | printf "%q"}}{{end}}{{end}}')"
container_exists="$?"
# Does the container exists? check if inspect reported errors
if [ "${container_exists}" -gt 0 ]; then
@@ -375,6 +375,17 @@ if [ "${container_status}" != "running" ]; then
#
# In the end, print eventual Warnings that occurred.
while :; do
# Check if the container is going in error status at any time during the first init
if [ "$(${container_manager} inspect \
--type container "${container_name}" \
--format "{{.State.Status}}")" != "running" ]; then
container_manager_log="$(${container_manager} logs "${container_name}")"
printf >&2 "%s\n" "${container_manager_log}"
exit 1
fi
container_manager_log="$(${container_manager} logs -t \
--since "${log_timestamp}" \
"${container_name}" 2> /dev/null)"