如何更改docker映像安装目录?

时间:2022-07-17 22:58:06

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映像被安装到/var/lib/docker中。是否有办法改变这个位置,比如像/mnt这样的挂载卷?

16 个解决方案

#1


99  

With recent versions of Docker, you would set the value of the graph parameter to your custom path, in /etc/docker/daemon.json (according to https://docs.docker.com/v1.11/engine/reference/commandline/daemon/#daemon-configuration-file).

使用Docker的最新版本,您可以将图形参数的值设置为/etc/ docker/daemon。json(据https://docs.docker.com/v1.11/engine/reference/commandline/daemon/ # daemon-configuration-file)。

With older versions, you can change Docker's storage base directory (where container and images go) using the -goption when starting the Docker daemon. (check docker --help). You can have this setting applied automatically when Docker starts by adding it to /etc/default/docker

使用旧版本,您可以在启动Docker守护进程时使用-goption更改Docker的存储库目录(其中容器和图像)。(检查码头工人——帮助)。当Docker开始将它添加到/etc/default/docker时,可以自动地应用该设置。

#2


91  

Following advice from comments I utilize Docker systemd documentation to improve this answer. Below procedure doesn't require reboot and is much cleaner.

下面的建议我利用Docker systemd文档来改进这个答案。下面的程序不需要重新启动,而且更干净。

First create directory and file for custom configuration:

首先为自定义配置创建目录和文件:

sudo mkdir -p /etc/systemd/system/docker.service.d
sudo $EDITOR /etc/systemd/system/docker.service.d/docker-storage.conf

For docker version before 17.06-ce paste:

在17.06-ce粘贴之前的docker版本:

[Service]
ExecStart=
ExecStart=/usr/bin/docker daemon -H fd:// --graph="/mnt"

For docker after 17.06-ce paste:

17.06-ce粘贴后的docker:

[Service]
ExecStart=
ExecStart=/usr/bin/dockerd -H fd:// --data-root="/mnt"

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:

我最近在Fedora 25上尝试了17.09-ce的程序,但似乎没有效果。而不是简单地修改/etc/ docker/daemon。json的诀窍:

{
    "graph": "/mnt",
    "storage-driver": "overlay"
}

Despite the method you have to reload configuration and restart Docker:

尽管您必须重新加载配置并重新启动Docker:

sudo systemctl daemon-reload
sudo systemctl restart docker

To confirm that Docker was reconfigured:

确认Docker已重新配置:

docker info|grep "loop file"

In recent version (17.03) different command is required:

在最近的版本(17.03)中,需要不同的命令:

docker info|grep "Docker Root Dir"

Output should look like this:

输出应该是这样的:

 Data loop file: /mnt/devicemapper/devicemapper/data
 Metadata loop file: /mnt/devicemapper/devicemapper/metadata

Or:

或者:

 Docker Root Dir: /mnt

Then you can safely remove old Docker storage:

然后您可以安全地删除旧的Docker存储:

rm -rf /var/lib/docker

#3


32  

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:

因为我还没有找到在Fedora中做这个的正确的说明(编辑:人们在评论中指出这应该也适用于CentOS和Suse) (/etc/default/docker不在那里),我在这里添加了我的答案:

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:

您必须编辑/etc/sysconfig/docker,并在选项变量中添加-g选项。如果有不止一个选项,请确保将它们装入“”。在我的案例中,该文件包含:

OPTIONS=--selinux-enabled

so it would become

这将成为

OPTIONS="--selinux-enabled -g /mnt"

After a restart (systemctl restart docker) , Docker should use the new directory

重启(systemctl restart docker)后,docker应该使用新目录。

#4


21  

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.

不要使用符号链接将docker文件夹移到/mnt(例如)。这可能会引起docker rm命令的麻烦。

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.

对于docker最好使用-g选项。在Ubuntu上,你可以将它永久设置为/etc/default/docker.io。增强或替换DOCKER_OPTS行。

Here an example: `DOCKER_OPTS="-g /mnt/somewhere/else/docker/"

这里有一个例子:DOCKER_OPTS="-g /mnt/某处/else/docker/"

#5


10  

In CentOS 6.5

在CentOS 6.5

service docker stop
mkdir /data/docker  (new directory)
vi /etc/sysconfig/docker

add following line

添加以下行

other_args=" -g /data/docker -p /var/run/docker.pid"

then save the file and start docker again

然后保存文件并再次启动docker。

service docker start

and will make repository file in /data/docker

并将存储库文件/数据/docker。

#6


7  

This solution works on Red Hat 7.2 & Docker 1.12.0

这个解决方案适用于Red Hat 7.2和Docker 1.12.0。

Edit the file /lib/systemd/system/docker.service in your text editor.

编辑该文件/lib/systemd/system/docker.在文本编辑器中提供服务。

add -g /path/to/docker/ at the end of ExecStart directive. The complete line should look like this.

添加-g /path/to/docker/在ExecStart指令的末尾。完整的线应该是这样的。

ExecStart=/usr/bin/dockerd -g /path/to/docker/

Execute the below command

执行以下命令

systemctl daemon-reload
systemctl restart docker

Execute the command to check docker directory

执行命令检查docker目录。

docker info | grep "loop file\|Dir"

If you have /etc/sysconfig/docker file in Red Hat or docker 1.7.1 check this answer.

如果您有/etc/sysconfig/docker文件在红帽或docker 1.7.1检查这个答案。

#7


6  

For Debian/Ubuntu or Fedora, you can probably use the other answers. But if you don't have files under /etc/default/docker or /etc/sysconfig/docker, and your system is running systemd, you may want to follow this answer by h3nrik. I am using Arch, and this works for me.

对于Debian/Ubuntu或Fedora,您可能会使用其他的答案。但是如果您没有在/etc/default/docker或/etc/sysconfig/docker下的文件,并且您的系统正在运行systemd,那么您可能想要按照h3nrik的方法来执行这个答案。我用的是Arch,这对我有用。

Basically, you need to configure systemd to read the new docker image location as an environment variable, and pass that environment variable into the Docker daemon execution script.

基本上,您需要配置systemd以将新的docker映像位置作为环境变量读取,并将该环境变量传递到docker守护进程执行脚本中。

For completeness, here is h3nrick's answer:

为了完整性,这里是h3nrick的答案:


Do you have a /lib/systemd/system/docker.service file?

你有/lib/ systemd/system/docker吗?服务文件?

If so, edit it so that the Docker service uses the usual /etc/default/docker as an environment file: EnvironmentFile=-/etc/default/docker.

如果是这样,编辑它以便Docker服务使用通常的/etc/default/docker作为环境文件:environment file =-/etc/default/ Docker。

In the /etc/default/docker file then add DOCKER_OPTS="-g /home/rseixas/Programs/Docker/images".

在/etc/default/docker文件中,然后添加DOCKER_OPTS=“-g /home/rseixas/Programs/Docker/images”。

At the end just do a systemctl daemon-reload && systemctl restart docker.

最后,做一个systemctl daemon-reload && systemctl重新启动docker。

For further information please also have a look at the documentation.

有关进一步的信息,请参阅文档。

#8


6  

Copy-and-paste version of the winner answer :)

胜利者回答的复制-粘贴版本:)

Create this file with only this content:

创建此文件仅包含以下内容:

$ sudo vi /etc/docker/daemon.json

$ sudo vi /etc/docker/daemon.json

  {
      "graph": "/my-docker-images"
  }

Tested on Ubuntu 16.04.2 LTS in docker 1.12.6

在docker 1.12.6上测试Ubuntu 16.04.2 LTS。

#9


5  

A much simpler solution is to create a soft link point to whatever you want, such as

一个更简单的解决方案是创建一个软链接指向您想要的任何东西,比如。

link -s /var/lib/docker /mnt/whatever

It works for me on my CentOS 6.5 server.

它在我的CentOS 6.5服务器上为我工作。

#10


1  

On an AWS Ubuntu 16.04 Server I put the Docker images on a separate EBS, mounted on /home/ubuntu/kaggle/, under the docker dir

在AWS Ubuntu 16.04服务器上,我将Docker映像放在一个单独的EBS上,安装在Docker dir下的/home/ubuntu/kaggle/上。

This snippet of my initialization script worked correctly

我的初始化脚本的这个片段工作正常。

# where are the images initially stored?
sudo docker info | grep "Root Dir"
# ... not where I want them

# modify the configuration files to change to image location
# NOTE this generates an error
# WARNING: Usage of loopback devices is strongly discouraged for production use.
#          Use `--storage-opt dm.thinpooldev` to specify a custom block storage device.
# see https://*.com/questions/31620825/
#     warning-of-usage-of-loopback-devices-is-strongly-discouraged-for-production-use

sudo sed -i   ' s@#DOCKER_OPTS=.*@DOCKER_OPTS="-g /home/ubuntu/kaggle/docker"@ '  /etc/default/docker

sudo chmod -R ugo+rw /lib/systemd/system/docker.service
sudo cp  /lib/systemd/system/docker.service /etc/systemd/system/
sudo chmod -R ugo+rw /etc/systemd/system/

sudo sed -i ' s@ExecStart.*@ExecStart=/usr/bin/dockerd $DOCKER_OPTS -H fd://@ '  /etc/systemd/system/docker.service
sudo sed -i '/ExecStart/a EnvironmentFile=-/etc/default/docker' /etc/systemd/system/docker.service
sudo systemctl daemon-reload
sudo systemctl restart docker
sudo docker info | grep "Root Dir"
# now they're where I want them

#11


1  

On openSUSE Leap 42.1

在openSUSE 42.1飞跃

$cat /etc/sysconfig/docker 
## Path           : System/Management
## Description    : Extra cli switches for docker daemon
## Type           : string
## Default        : ""
## ServiceRestart : docker
#
DOCKER_OPTS="-g /media/data/installed/docker"

Note that DOCKER_OPTS was initially empty and all I did was add in the argument to make docker use my new directory

注意,DOCKER_OPTS最初是空的,我所做的只是在参数中添加,使docker使用我的新目录。

#12


1  

As recommneded by @mbarthelemy this can be done via the -g option when starting the docker daemon directly.

通过@mbarthelemy的推荐,可以通过-g选项直接启动docker守护进程。

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.

但是,如果docker作为一个系统服务启动,则不建议修改/etc/default/docker文件。这里有一个指导方针。

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:

正确的方法是创建一个/etc/ docker/daemon。在Linux(或Mac)系统上的json文件或%programdata%\docker\config\daemon。json在Windows。如果这个文件没有被用于其他任何东西,下面的字段就足够了:

{
    "graph": "/docker/daemon_files"
}

This is assuming the new location where you want to have docker persist its data is /docker/daemon_files

这是假设您希望有docker的新位置保存它的数据是/docker/daemon_files。

#13


0  

For Mac users in the 17.06.0-ce-mac19 version you can simply move the Disk Image location from the user interface in the preferences option Just change the location of the disk image and it will work (by clicking Move disk Image) and restarting the docker. Using this approach I was able to use my external hardisk for storing docker images.

对于17.06.0-ce-mac19版本的Mac用户,您只需将磁盘映像位置从首选项选项中移动到用户界面即可,只需更改磁盘映像的位置,即可工作(通过单击移动磁盘映像)并重新启动docker。使用这种方法,我可以使用我的外部硬盘来存储docker映像。

如何更改docker映像安装目录?

#14


0  

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.

在Fedora 26和其他许多版本中,您可能会在移动您的基本文件夹位置之后遇到一个错误。如果你把它搬到某个地方或家里,这一点尤其正确。这是因为SeLinux启动并阻止docker容器从这个位置运行它的许多程序。

The short solution is to remove the --enable-selinux option when you add the -g parameter.

简短的解决方案是在添加-g参数时删除-enable-selinux选项。

#15


0  

Much easier way to do so:

Stop docker service

码头工人停止服务

sudo systemctl stop docker

Move existing docker directory to new location

将现有的docker目录移动到新的位置。

sudo mv /var/lib/docker/ /path/to/new/docker/

Create symbolic link

创建符号链接

sudo ln -s /path/to/new/docker/ /var/lib/docker/

Start docker service

启动码头工人服务

sudo systemctl start docker

#16


0  

For new docker versions we need to use data-root as from the official deprecated docs (Deprecated In Release: v17.05.0)

对于新的docker版本,我们需要使用数据根,就像来自官方的弃用文档(在发布中弃用:v17.05.0)

{
  "data-root": "/new/path/to/docker-data"
}
  • Changing Docker Storage with data-root: my most helpful Post with steps to follow
  • 使用数据根更改Docker存储:我最有帮助的一篇文章。
  • In case of Windows a similar post Windows specific
  • 如果是Windows,类似的后窗是特定的。

#1


99  

With recent versions of Docker, you would set the value of the graph parameter to your custom path, in /etc/docker/daemon.json (according to https://docs.docker.com/v1.11/engine/reference/commandline/daemon/#daemon-configuration-file).

使用Docker的最新版本,您可以将图形参数的值设置为/etc/ docker/daemon。json(据https://docs.docker.com/v1.11/engine/reference/commandline/daemon/ # daemon-configuration-file)。

With older versions, you can change Docker's storage base directory (where container and images go) using the -goption when starting the Docker daemon. (check docker --help). You can have this setting applied automatically when Docker starts by adding it to /etc/default/docker

使用旧版本,您可以在启动Docker守护进程时使用-goption更改Docker的存储库目录(其中容器和图像)。(检查码头工人——帮助)。当Docker开始将它添加到/etc/default/docker时,可以自动地应用该设置。

#2


91  

Following advice from comments I utilize Docker systemd documentation to improve this answer. Below procedure doesn't require reboot and is much cleaner.

下面的建议我利用Docker systemd文档来改进这个答案。下面的程序不需要重新启动,而且更干净。

First create directory and file for custom configuration:

首先为自定义配置创建目录和文件:

sudo mkdir -p /etc/systemd/system/docker.service.d
sudo $EDITOR /etc/systemd/system/docker.service.d/docker-storage.conf

For docker version before 17.06-ce paste:

在17.06-ce粘贴之前的docker版本:

[Service]
ExecStart=
ExecStart=/usr/bin/docker daemon -H fd:// --graph="/mnt"

For docker after 17.06-ce paste:

17.06-ce粘贴后的docker:

[Service]
ExecStart=
ExecStart=/usr/bin/dockerd -H fd:// --data-root="/mnt"

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:

我最近在Fedora 25上尝试了17.09-ce的程序,但似乎没有效果。而不是简单地修改/etc/ docker/daemon。json的诀窍:

{
    "graph": "/mnt",
    "storage-driver": "overlay"
}

Despite the method you have to reload configuration and restart Docker:

尽管您必须重新加载配置并重新启动Docker:

sudo systemctl daemon-reload
sudo systemctl restart docker

To confirm that Docker was reconfigured:

确认Docker已重新配置:

docker info|grep "loop file"

In recent version (17.03) different command is required:

在最近的版本(17.03)中,需要不同的命令:

docker info|grep "Docker Root Dir"

Output should look like this:

输出应该是这样的:

 Data loop file: /mnt/devicemapper/devicemapper/data
 Metadata loop file: /mnt/devicemapper/devicemapper/metadata

Or:

或者:

 Docker Root Dir: /mnt

Then you can safely remove old Docker storage:

然后您可以安全地删除旧的Docker存储:

rm -rf /var/lib/docker

#3


32  

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:

因为我还没有找到在Fedora中做这个的正确的说明(编辑:人们在评论中指出这应该也适用于CentOS和Suse) (/etc/default/docker不在那里),我在这里添加了我的答案:

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:

您必须编辑/etc/sysconfig/docker,并在选项变量中添加-g选项。如果有不止一个选项,请确保将它们装入“”。在我的案例中,该文件包含:

OPTIONS=--selinux-enabled

so it would become

这将成为

OPTIONS="--selinux-enabled -g /mnt"

After a restart (systemctl restart docker) , Docker should use the new directory

重启(systemctl restart docker)后,docker应该使用新目录。

#4


21  

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.

不要使用符号链接将docker文件夹移到/mnt(例如)。这可能会引起docker rm命令的麻烦。

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.

对于docker最好使用-g选项。在Ubuntu上,你可以将它永久设置为/etc/default/docker.io。增强或替换DOCKER_OPTS行。

Here an example: `DOCKER_OPTS="-g /mnt/somewhere/else/docker/"

这里有一个例子:DOCKER_OPTS="-g /mnt/某处/else/docker/"

#5


10  

In CentOS 6.5

在CentOS 6.5

service docker stop
mkdir /data/docker  (new directory)
vi /etc/sysconfig/docker

add following line

添加以下行

other_args=" -g /data/docker -p /var/run/docker.pid"

then save the file and start docker again

然后保存文件并再次启动docker。

service docker start

and will make repository file in /data/docker

并将存储库文件/数据/docker。

#6


7  

This solution works on Red Hat 7.2 & Docker 1.12.0

这个解决方案适用于Red Hat 7.2和Docker 1.12.0。

Edit the file /lib/systemd/system/docker.service in your text editor.

编辑该文件/lib/systemd/system/docker.在文本编辑器中提供服务。

add -g /path/to/docker/ at the end of ExecStart directive. The complete line should look like this.

添加-g /path/to/docker/在ExecStart指令的末尾。完整的线应该是这样的。

ExecStart=/usr/bin/dockerd -g /path/to/docker/

Execute the below command

执行以下命令

systemctl daemon-reload
systemctl restart docker

Execute the command to check docker directory

执行命令检查docker目录。

docker info | grep "loop file\|Dir"

If you have /etc/sysconfig/docker file in Red Hat or docker 1.7.1 check this answer.

如果您有/etc/sysconfig/docker文件在红帽或docker 1.7.1检查这个答案。

#7


6  

For Debian/Ubuntu or Fedora, you can probably use the other answers. But if you don't have files under /etc/default/docker or /etc/sysconfig/docker, and your system is running systemd, you may want to follow this answer by h3nrik. I am using Arch, and this works for me.

对于Debian/Ubuntu或Fedora,您可能会使用其他的答案。但是如果您没有在/etc/default/docker或/etc/sysconfig/docker下的文件,并且您的系统正在运行systemd,那么您可能想要按照h3nrik的方法来执行这个答案。我用的是Arch,这对我有用。

Basically, you need to configure systemd to read the new docker image location as an environment variable, and pass that environment variable into the Docker daemon execution script.

基本上,您需要配置systemd以将新的docker映像位置作为环境变量读取,并将该环境变量传递到docker守护进程执行脚本中。

For completeness, here is h3nrick's answer:

为了完整性,这里是h3nrick的答案:


Do you have a /lib/systemd/system/docker.service file?

你有/lib/ systemd/system/docker吗?服务文件?

If so, edit it so that the Docker service uses the usual /etc/default/docker as an environment file: EnvironmentFile=-/etc/default/docker.

如果是这样,编辑它以便Docker服务使用通常的/etc/default/docker作为环境文件:environment file =-/etc/default/ Docker。

In the /etc/default/docker file then add DOCKER_OPTS="-g /home/rseixas/Programs/Docker/images".

在/etc/default/docker文件中,然后添加DOCKER_OPTS=“-g /home/rseixas/Programs/Docker/images”。

At the end just do a systemctl daemon-reload && systemctl restart docker.

最后,做一个systemctl daemon-reload && systemctl重新启动docker。

For further information please also have a look at the documentation.

有关进一步的信息,请参阅文档。

#8


6  

Copy-and-paste version of the winner answer :)

胜利者回答的复制-粘贴版本:)

Create this file with only this content:

创建此文件仅包含以下内容:

$ sudo vi /etc/docker/daemon.json

$ sudo vi /etc/docker/daemon.json

  {
      "graph": "/my-docker-images"
  }

Tested on Ubuntu 16.04.2 LTS in docker 1.12.6

在docker 1.12.6上测试Ubuntu 16.04.2 LTS。

#9


5  

A much simpler solution is to create a soft link point to whatever you want, such as

一个更简单的解决方案是创建一个软链接指向您想要的任何东西,比如。

link -s /var/lib/docker /mnt/whatever

It works for me on my CentOS 6.5 server.

它在我的CentOS 6.5服务器上为我工作。

#10


1  

On an AWS Ubuntu 16.04 Server I put the Docker images on a separate EBS, mounted on /home/ubuntu/kaggle/, under the docker dir

在AWS Ubuntu 16.04服务器上,我将Docker映像放在一个单独的EBS上,安装在Docker dir下的/home/ubuntu/kaggle/上。

This snippet of my initialization script worked correctly

我的初始化脚本的这个片段工作正常。

# where are the images initially stored?
sudo docker info | grep "Root Dir"
# ... not where I want them

# modify the configuration files to change to image location
# NOTE this generates an error
# WARNING: Usage of loopback devices is strongly discouraged for production use.
#          Use `--storage-opt dm.thinpooldev` to specify a custom block storage device.
# see https://*.com/questions/31620825/
#     warning-of-usage-of-loopback-devices-is-strongly-discouraged-for-production-use

sudo sed -i   ' s@#DOCKER_OPTS=.*@DOCKER_OPTS="-g /home/ubuntu/kaggle/docker"@ '  /etc/default/docker

sudo chmod -R ugo+rw /lib/systemd/system/docker.service
sudo cp  /lib/systemd/system/docker.service /etc/systemd/system/
sudo chmod -R ugo+rw /etc/systemd/system/

sudo sed -i ' s@ExecStart.*@ExecStart=/usr/bin/dockerd $DOCKER_OPTS -H fd://@ '  /etc/systemd/system/docker.service
sudo sed -i '/ExecStart/a EnvironmentFile=-/etc/default/docker' /etc/systemd/system/docker.service
sudo systemctl daemon-reload
sudo systemctl restart docker
sudo docker info | grep "Root Dir"
# now they're where I want them

#11


1  

On openSUSE Leap 42.1

在openSUSE 42.1飞跃

$cat /etc/sysconfig/docker 
## Path           : System/Management
## Description    : Extra cli switches for docker daemon
## Type           : string
## Default        : ""
## ServiceRestart : docker
#
DOCKER_OPTS="-g /media/data/installed/docker"

Note that DOCKER_OPTS was initially empty and all I did was add in the argument to make docker use my new directory

注意,DOCKER_OPTS最初是空的,我所做的只是在参数中添加,使docker使用我的新目录。

#12


1  

As recommneded by @mbarthelemy this can be done via the -g option when starting the docker daemon directly.

通过@mbarthelemy的推荐,可以通过-g选项直接启动docker守护进程。

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.

但是,如果docker作为一个系统服务启动,则不建议修改/etc/default/docker文件。这里有一个指导方针。

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:

正确的方法是创建一个/etc/ docker/daemon。在Linux(或Mac)系统上的json文件或%programdata%\docker\config\daemon。json在Windows。如果这个文件没有被用于其他任何东西,下面的字段就足够了:

{
    "graph": "/docker/daemon_files"
}

This is assuming the new location where you want to have docker persist its data is /docker/daemon_files

这是假设您希望有docker的新位置保存它的数据是/docker/daemon_files。

#13


0  

For Mac users in the 17.06.0-ce-mac19 version you can simply move the Disk Image location from the user interface in the preferences option Just change the location of the disk image and it will work (by clicking Move disk Image) and restarting the docker. Using this approach I was able to use my external hardisk for storing docker images.

对于17.06.0-ce-mac19版本的Mac用户,您只需将磁盘映像位置从首选项选项中移动到用户界面即可,只需更改磁盘映像的位置,即可工作(通过单击移动磁盘映像)并重新启动docker。使用这种方法,我可以使用我的外部硬盘来存储docker映像。

如何更改docker映像安装目录?

#14


0  

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.

在Fedora 26和其他许多版本中,您可能会在移动您的基本文件夹位置之后遇到一个错误。如果你把它搬到某个地方或家里,这一点尤其正确。这是因为SeLinux启动并阻止docker容器从这个位置运行它的许多程序。

The short solution is to remove the --enable-selinux option when you add the -g parameter.

简短的解决方案是在添加-g参数时删除-enable-selinux选项。

#15


0  

Much easier way to do so:

Stop docker service

码头工人停止服务

sudo systemctl stop docker

Move existing docker directory to new location

将现有的docker目录移动到新的位置。

sudo mv /var/lib/docker/ /path/to/new/docker/

Create symbolic link

创建符号链接

sudo ln -s /path/to/new/docker/ /var/lib/docker/

Start docker service

启动码头工人服务

sudo systemctl start docker

#16


0  

For new docker versions we need to use data-root as from the official deprecated docs (Deprecated In Release: v17.05.0)

对于新的docker版本,我们需要使用数据根,就像来自官方的弃用文档(在发布中弃用:v17.05.0)

{
  "data-root": "/new/path/to/docker-data"
}
  • Changing Docker Storage with data-root: my most helpful Post with steps to follow
  • 使用数据根更改Docker存储:我最有帮助的一篇文章。
  • In case of Windows a similar post Windows specific
  • 如果是Windows,类似的后窗是特定的。