That sounded pretty simple, but it turned out to be a vexing problem.
After moving the directory, I ran a Docker container that contained an instance of Drupal 7. When I browsed to the Drupal site I got the error:
Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock'If you do a web search on this error message, there are a lot of possible causes. In my case, the Docker container had been running fine just before the directory move, so that was an obvious culprit.
I had typed in several cp commands before running the container again, but I didn't have a clear memory or record of the steps I had taken. After the first occurrence of the error, I did further copy commands. The error kept occurring, but once in a while the site came up okay. This thrashing about included my re-initializing the docker directory at least once.
From my frustrating experience, here are a few suggestions about moving Docker's storage.
(a) Be sure to stop the Docker service before making any changes.
(b) Use Docker's configuration file and the -g option to indicate the location of storage. This provides both flexibility and safety in trying different locations.
(c) If you use the cp command to copy storage contents, be sure to include the -p option to preserve owner, mode, and timestamp.
Here's an example of a sequence of steps that has worked in moving the Docker storage folder to a different location by using cp.
(1) Stop the Docker service.
# service docker stop
(2) Copy Docker's storage folder to a different partition.
# cd /var/lib
# cp -r -p docker /home/earl
# mv docker docker-save
(3) Edit the Docker configuration file to add the -g option to point to the new location. The file may already contain a commented line you can use as a starting point.
# vim /etc/default/docker
DOCKER_OPTS="--dns 184.108.40.206 --dns 220.127.116.11 -g /home/earl/docker"
(4) Re-start the Docker service. Run your container to test the change.
# service docker start
(5) When you are confident that the change is correct, you can remove the original directory to recover the space.
# rm -r /var/lib/docker-save
How do I change the Docker image installation directory?