Docker: Container keeps on restarting again on again
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
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.
This could also be the case if you have created a systemd
service that has:
[Service]
Restart=always
ExecStart=/usr/bin/docker container start -a my_container
ExecStop=/usr/bin/docker container stop -t 2 my_container
From personal experience it sounds like there is a problem within your docker container that is not allowing it to restart. So some process within the container is causing the restart to hang or some process is causing the container to crash on start.
When you start the container make sure you start it detached "-d" if you are going to attach to it. (ex. "docker run -d mediawiki_web_1")