Feature request: wait for Docker container to be running
Thanks for this great tool! It really simplifies cross-platform scripting.
Sometimes I use the following pattern in a bash script to wait for a Docker container to be running:
until [[ "$(docker inspect -f "{{.State.Running}}" my_container_name)" == "true" ]]; do
sleep 0.1;
done;
It just waits until the container's Running state is true.
It would be great if wait4x could do this instead:
wait4x container my_container_name_or_id
With the new exec command, a variant of this would probably look like:
# I doubt this will work correctly in a cross-platform way due to shell expansion and requiring that `test` exists
wait4x exec 'test "$(docker inspect -f "{{.State.Running}}" my_container_name_or_id)" == "true"'
# This could work if you have a justfile that implements a check-running recipe (but it would still require the justfile to resolve any cross-platform differences)
wait4x exec 'just check-running'
The following Docker container states exist:
Enum: "created" "running" "paused" "restarting" "removing" "exited" "dead"
More information:
- https://docs.docker.com/reference/api/engine/version/v1.50/#tag/Container/operation/ContainerInspect
- https://pkg.go.dev/github.com/docker/docker/client
- https://github.com/containers/podman/blob/main/pkg/bindings/README.md#inspect-a-container
Hey @W1M0R, thanks for your suggestion! It’s a really nice feature. By the way, we’d be happy if you want to contribute to it. If not, no worries — we can also consider adding it in the near future.
Thanks @atkrad