Docker: Container keeps on restarting again on again
In my case i removed
Restart=always
added
tty: true
And executed the below command to open shell (daemon process, because docker reads the compose file and stops the container once it reaches the last line of the file).
docker-compose up -d
tl;dr It is restarting with a status code of 127
, meaning there is a missing file/library in your container. Starting a fresh container just might fix it.
Explanation:
As far as my understanding of Docker goes, this is what is happening:
- Container tries to start up. In the process, it tries to access a file/library which does not exist.
- It exits with a status code of
127
, which is explained in this answer. - Normally, this is where the container should have completely exited, but it restarts.
- It restarts because the restart policy must have been set to something other than
no
(the default), (using either the command line flag--restart
or thedocker-compose.yml
keyrestart
) while starting the container.
Solution: Something might have corrupted your container. Starting a fresh container should ideally do the job.
The docker logs
command will show you the output a container is generating when you don't run it interactively. This is likely to include the error message.
docker logs --tail 50 --follow --timestamps mediawiki_web_1
You can also run a fresh container in the foreground with docker run -ti <your_wiki_image>
to see what that does. You may need to map some config from your docker-compose
yml to the docker
command.
I would guess that attaching to the media wiki process caused a crash which has corrupted something in your data.
When docker kill CONTAINER_ID
does not work and docker stop -t 1 CONTAINER_ID
also does not work, you can try to delete the container:
docker container rm CONTAINER_ID
I had a similar issue today where containers were in a continuous restart loop.
The issue in my case was related to me being a poor engineer.
Anyway, I fixed the issue by deleting the container, fixing my code, and then rebuilding and running the container.
Hope that this helps anyone stuck with this issue in future