Temporary Trick to Keep Docker Desktop Working Correctly on Ubuntu(24.04+; including 24.10) Without Losing Data ๐ณ๐
This script provides a temporary workaround to make Docker Desktop function "correctly" on Ubuntu 24.04+ without losing volumes, images, or containers. It helps avoid the common issue where Docker Desktop fails to start, requiring users to delete ~/.docker
or reinstall Docker Desktop repeatedly to make it work again.
When Ubuntu starts or a user logs in, the script checks if Docker Desktop is running. If Docker is NOT running, it deletes a specific file that may be preventing it from starting correctly. This trick avoids unnecessary resets and ensures Docker Desktop can start properly without erasing your existing containers, images, or volumes. It also runs before shutdown or reboot, ensuring a clean state for the next session.
- No need to delete
~/.docker
manually - Preserves your containers, images, and volumes
- Avoids constant reinstallations of Docker Desktop
- Fully automated at startup, login, and shutdown
Save the following script as /usr/local/bin/check_docker.sh
:
#!/bin/bash
FILE_TO_REMOVE="/home/$USER/.docker/desktop/settings-store.json"
if ! pgrep -x "Docker Desktop" > /dev/null; then
if [ -f "$FILE_TO_REMOVE" ]; then
rm -f "$FILE_TO_REMOVE"
fi
fi
sudo chmod +x /usr/local/bin/check_docker.sh
Create a systemd service file:
sudo nano /etc/systemd/system/check_docker.service
Add the following content:
[Unit]
Description=Checks if Docker is running and deletes a file if not
After=network.target
Before=shutdown.target reboot.target halt.target
[Service]
Type=oneshot
ExecStart=/usr/local/bin/check_docker.sh
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target shutdown.target reboot.target halt.target
Save the file (press Ctrl + X, then Y, and Enter).
Run these commands to enable and start the service:
sudo systemctl daemon-reload
sudo systemctl enable check_docker.service
sudo systemctl start check_docker.service
To execute the script when a user logs in, add the following line to your ~/.bashrc
or ~/.bash_profile
:
/usr/local/bin/check_docker.sh
If you want it to run when a graphical session starts, add it to ~/.profile
:
echo "/usr/local/bin/check_docker.sh" >> ~/.profile
To manually test the script, run:
/usr/local/bin/check_docker.sh
To check the systemd service status:
systemctl status check_docker.service
- Checks if Docker Desktop is running
- Deletes a file if Docker is not active
- Runs at system startup, before shutdown, and on user login