Error response from daemon: Container ... is restarting, wait until the container is running means the container's main command keeps failing and its restart policy keeps starting it again, so there is never a running container to exec into. Waiting does not help. Read docker logs for the reason, and debug in a new container with the command overridden.

To end the loop, switch the policy off with docker update --restart no and stop the container. Then fix what the logs complain about and start it again.

The error

PS> docker run -d --name fix9-run-loop --restart always alpine sh -c "echo starting; cat /config/app.json"
79618c440d2d782ce2fbf95775267709b4cb7b9bf112b5bcc3146872995e30d0
...
PS> docker exec fix9-run-loop ls /
Error response from daemon: Container 79618c440d2d782ce2fbf95775267709b4cb7b9bf112b5bcc3146872995e30d0 is restarting, wait until the container is running

PS> docker ps -a --filter name=fix9-run-loop --format "{{.Names}} {{.Status}}"
fix9-run-loop Restarting (1) Less than a second ago

Why it happens

The command reads a file that is not in the image, exits with code 1, and --restart always starts it again. docker ps shows Restarting (1), where the number is the last exit code. A few seconds after the start, docker inspect already counted six restarts:

PS> docker logs --tail 4 fix9-run-loop
starting
cat: can't open '/config/app.json': No such file or directory
cat: can't open '/config/app.json': No such file or directory
starting

PS> docker inspect fix9-run-loop --format "Status={{.State.Status}} Restarting={{.State.Restarting}} ExitCode={{.State.ExitCode}} RestartCount={{.RestartCount}} Policy={{.HostConfig.RestartPolicy.Name}}"
Status=restarting Restarting=true ExitCode=1 RestartCount=6 Policy=always

docker logs worked on the restarting container and showed the output of more than one attempt, with the reason in plain words: the file is missing.

The fix

Look inside the image with the same image and a command that does not fail:

PS> docker run --rm --name fix9-run-debug alpine sh -c "ls /config; echo shell works"
ls: /config: No such file or directory
shell works

That container ran, so you can check paths and files that the failing command expects. In a terminal, docker run -it --rm with sh as the command gives an interactive shell instead; the test ran without a terminal, so it passed the commands with -c. Then stop the loop:

PS> docker update --restart no fix9-run-loop
fix9-run-loop

PS> docker stop fix9-run-loop
fix9-run-loop

PS> docker ps -a --filter name=fix9-run-loop --format "{{.Names}} {{.Status}}"
fix9-run-loop Exited (1) 2 seconds ago

Here the fix is to provide the file, for example with a bind mount to /config/app.json, and run the container again.

How it was reproduced

On Windows 11 with Docker Desktop, engine and client 29.9.3, from Windows PowerShell 5.1, with the cached alpine image. A container with --restart always ran a command that read a missing file; four seconds later docker exec gave the error above, docker logs showed the reason and docker inspect a RestartCount of 6. docker update --restart no and docker stop left it Exited (1). The container names are the test's own.

Frequently asked

How do I see why a Docker container keeps restarting?
Run docker logs on it; it showed the output of several attempts here, including the error line. docker inspect shows the last ExitCode and the RestartCount.
How do I get a shell in a container that keeps restarting?
You cannot exec into it while it restarts. Run a new container from the same image with the command overridden, for example docker run --rm alpine sh -c with your checks, or -it with sh in a terminal.
How do I stop a Docker restart loop?
Run docker update --restart no on the container, then docker stop. In this test the container then stayed Exited (1).

More decoded errors in the Fixes category. Another docker exec message, about a container that is not running at all: container is not running.