Preface
During work, I encountered the problem that the service deployed by docker suddenly stopped. After ssh checked, I realized that the mirror and container were gone. If I encountered these problems,
You can refer to the steps to solve it. First check whether the storage space of the docker installed directory is full. If it is full, please see Method 2. If it is not full, you can try Method 1.
Method 1. Replace
- Modify /etc/docker/ to make it illegal, and then execute systemctl restart docker. Docker will report an error at this time
- Restore normal /etc/docker/, then execute systemctl daemon-reload, systemctl restart docker
Method 2. Replace the docker installation directory
To change the installation directory of Docker (i.e., the directory where Docker stores its containers, images, volumes, and networks) to/data
Next, you need to follow the steps:
2.1 Stop Docker Service
First, stop the Docker service to ensure that there are no conflicts when changing configurations.
sudo systemctl stop docker
2.2 Create a new Docker directory
exist/data
Create a new directory to store Docker data.
sudo mkdir -p /data/docker
2.3 Modify Docker configuration file
Edit Docker's configuration file, usually located in/etc/docker/
. If the file does not exist, you can create a new one.
sudo nano /etc/docker/
Add or modify the following content in the file to set the Docker data root directory to/data/docker
:
{ "data-root": "/data/docker" }
If there are other configuration items in the file, make sure that the JSON is formatted correctly. For example:
{ "data-root": "/data/docker", "other-config": "value" }
2.4 Copy existing Docker data
If you already have some Docker data (containers, mirrors, etc.), you need to copy them to a new directory.
sudo rsync -aP /var/lib/docker/ /data/docker/
2.5 Start Docker Service
Restart the Docker service to apply the changes.
sudo systemctl start docker
2.6 Verify changes
Verify that Docker is using the new data directory.
docker info | grep "Docker Root Dir"
The output should show the new Docker root directory as/data/docker
。
2.7 Cleaning old data directory (optional)
If you confirm that everything is working and you no longer need the old Docker data directory, you can delete it to free up space.
sudo rm -rf /var/lib/docker
Summarize
Through the above steps, you can change the Docker installation directory to/data
Down. This includes stopping the Docker service, modifying configuration files, copying existing data, restarting the service, and verifying changes. Make sure to be careful when performing these operations, especially when processing existing data.
This is the article about the solution to docker images and container disappearance. For more related docker images and container disappearance content, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!