From what I can tell, docker images are installed to /var/lib/docker
as they are pulled. Is there a way to change this location, such as to a mounted volume like /mnt
?
相关问题
- Docker task in Azure devops won't accept "$(pw
- Unable to run mariadb when mount volume
- Unspecified error (0x80004005) while running a Doc
- What would prevent code running in a Docker contai
- How to reload apache in php-apache docker containe
Since I haven't found the correct instructions for doing this in Fedora (EDIT: people pointed in comments that this should also work on CentOS and Suse) (/etc/default/docker isn't used there), I'm adding my answer here:
You have to edit /etc/sysconfig/docker, and add the -g option in the OPTIONS variable. If there's more than one option, make sure you enclose them in "". In my case, that file contained:
so it would become
After a restart (
systemctl restart docker
) , Docker should use the new directoryAs recommneded by @mbarthelemy this can be done via the
-g
option when starting the docker daemon directly.However, if docker is being started as a system service, it is not recommended to modify the
/etc/default/docker
file. There is a guideline to this located here.The correct approach is to create an
/etc/docker/daemon.json
file on Linux (or Mac) systems or%programdata%\docker\config\daemon.json
on Windows. If this file is not being used for anything else, the following fields should suffice:This is assuming the new location where you want to have docker persist its data is
/docker/daemon_files
On Fedora 26 and probably many other versions, you may encounter an error after moving your base folder location as described above. This is particularly true if you are moving it to somewhere under /home. This is because SeLinux kicks in and prevents the docker container from running many of its programs from under this location.
The short solution is to remove the --enable-selinux option when you add the -g parameter.
Following advice from comments I utilize Docker systemd documentation to improve this answer. Below procedure doesn't require reboot and is much cleaner.
First create directory and file for custom configuration:
For docker version before 17.06-ce paste:
For docker after 17.06-ce paste:
Alternative method through
daemon.json
I recently tried above procedure with 17.09-ce on Fedora 25 and it seem to not work. Instead of that simple modification in
/etc/docker/daemon.json
do the trick:Despite the method you have to reload configuration and restart Docker:
To confirm that Docker was reconfigured:
In recent version (17.03) different command is required:
Output should look like this:
Or:
Then you can safely remove old Docker storage:
Much easier way to do so:
Stop docker service
Move existing docker directory to new location
Create symbolic link
Start docker service
Don't use a symbolic Link to move the docker folder to /mnt (for example). This may cause in trouble with the docker rm command.
Better use the -g Option for docker. On Ubuntu you can set it permanently in /etc/default/docker.io. Enhance or replace the DOCKER_OPTS Line.
Here an example: `DOCKER_OPTS="-g /mnt/somewhere/else/docker/"