落絮飞雁

顺流而下,把梦做完

Docker Container Restarting after SSH Login – Solution

As mentioned in a previous blog post, my current project is deployed using Docker. However, during a recent login to the server, a strange phenomenon occurred: all the containers in Docker would restart from time to time. Also, every time I logged in to check the Docker status, it would show that the containers had just started (Up 15 seconds). After several investigations, I finally identified that the restart issue was related to SSH login. Every time I logged in via SSH, the containers would restart.

My server is an Oracle ARM instance running Ubuntu 22.04. After searching online, I found that the restart issue was related to the rootless mode of Docker. When containers are started in user mode, they terminate after the user session is logged out. This is controlled by the system component loginctl.

The solution to this issue is quite simple: set the user who starts Docker to enable linger. The specific method to enable it is as follows:

loginctl enable-linger $UID

By enabling linger for the Docker user, the user’s session will not end immediately after logging out, allowing the containers to continue running. This will prevent the containers from restarting every time the user logs in via SSH.

In conclusion, if you encounter a similar issue where Docker containers keep restarting after SSH login, try enabling linger for the Docker user using the above method. It is a quick and easy solution that can save you a lot of time and trouble.

This post polished by ChatGPT, with images generated by Stable Diffusion.

Reference:


原文标题:Docker Container Restarting after SSH Login – Solution|落絮飞雁的个人网站
原文链接:https://www.luoxufeiyan.com/2023/03/05/docker-container-restarting-after-ssh-login-solution/
授权协议:创作共用 署名-非商业性使用 2.5 中国大陆
除注明外,本站文章均为原创;转载时请保留上述链接。