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:34

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).

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

查看更多
虎瘦雄心在
3楼-- · 2019-01-04 05:34

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

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://stackoverflow.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
查看更多
三岁会撩人
4楼-- · 2019-01-04 05:34

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.

查看更多
我命由我不由天
5楼-- · 2019-01-04 05:35

In 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

service docker start

and will make repository file in /data/docker

查看更多
家丑人穷心不美
6楼-- · 2019-01-04 05:35

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

{
  "data-root": "/new/path/to/docker-data"
}
  • Changing Docker Storage with data-root: my most helpful Post with steps to follow
  • In case of Windows a similar post Windows specific
查看更多
家丑人穷心不美
7楼-- · 2019-01-04 05:37

On openSUSE Leap 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

查看更多
登录 后发表回答