The disk space of the docker container stores the directory is full
When restarting docker on the Liunx server, I found that the container cannot be started, and the error reported is:
"ERROR:cannot create temporary directory!"
My guess is that the disk space is full, so I ran the command "df -h", and the result was that the mount point /var/lib/docker/overlay/ has % used as 100%, which is really the disk space has been used up.
What I don't understand is that my container has a configuration data volume. The dynamically grown data in the container, such as uploaded pictures and generated logs, are placed in the data volume. As usual, it will not cause the container to be full. Later, I asked the beauty of the company, and the beauty asked me to execute the command: docker ps -s to see if the container size is too large. If it is too large, it should be that the data volume has not been set.
I executed as the beauty said and found that the container size was the same as the size of the container I ran for the first time, which means that the data volume was set up successfully.
Then I continued to ask the beauty. The beauty asked who installed the docker. I went back and said that it was installed by myself and it was installed offline. The beauty said that you are the docker default directory and the docker default directory space is too small and it will be full in no time.
The default directory for storing images and containers in docker is: /var/lib/docker/, which is the guy I mentioned above whose mount is full. Since the reason has been found, then let's solve it.
Solution
It is to migrate all files under the default directory /var/lib/docker to the new directory, and then change the directory where docker stores the image and containers to a new directory.
My system is Centos7, and the specific steps to solve it are as follows:
1. Stop the docker service.
systemctl stop docker; //EachliunxDifferent versions of commands。
2. Create a new docker directory, execute the command df -h, and find a large disk.
Mine is placed under the /home directory, and my /home directory size is 900G.
I built the /home/docker/lib directory under the /home directory, and the command I executed is: mkdir -p /home/docker/lib
3. Migrate the files under the /var/lib/docker directory to the /home/docker/lib
cp -R /var/lib/docker/* /home/docker/lib/
Notice:
- If the file content is large, it is best to ensure success to copy one file by one.
- If an error is reported in the copy process, use mv cut.
4. Modify the docker configuration (/etc/systemd/system//), and add --graph=/home/docker/lib at the end of the file
The contents of the file are as follows:
[Service] ExecStart= ExecStart=/usr/bin/dockerd --insecure-registry=private Server address --graph=/home/docker/lib
Notice:
- If /etc/systemd/system//
- If this path cannot be found, create a new one. After the new one is created, add content. If there is no private server address, you can remove "--insecure-registry=private server address"
5. Reload the configuration and restart docker
systemctl daemon-reload; systemctl restart docker; systemctl enable docker;
6. After the startup is successful, after confirming that the container is fine, delete the files in the /var/lib/docker/ directory, and then it is OK.
Summarize
The above is personal experience. I hope you can give you a reference and I hope you can support me more.