How to change the docker image installation direct

2019-01-04 05:08发布

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
16条回答
爷、活的狠高调
2楼-- · 2019-01-04 05:48

This solution works on Red Hat 7.2 & Docker 1.12.0

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

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

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 info | grep "loop file\|Dir"

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

查看更多
别忘想泡老子
3楼-- · 2019-01-04 05:56

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

Create this file with only this content:

$ sudo vi /etc/docker/daemon.json

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

Tested on Ubuntu 16.04.2 LTS in docker 1.12.6

查看更多
叼着烟拽天下
4楼-- · 2019-01-04 05:56

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.

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.

For completeness, here is h3nrick's answer:


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

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

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

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

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

查看更多
混吃等死
5楼-- · 2019-01-04 05:59

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.

查看更多
登录 后发表回答