Docker修改默认存储位置

时间:2022-02-04 12:20:11

先Docker info 查看基本信息

root@ubuntu:~# docker info 
Containers: 2
 Running: 0
 Paused: 0
 Stopped: 2
Images: 39
Server Version: 18.05.0-ce
Storage Driver: overlay2
 Backing Filesystem: extfs
 Supports d_type: true
 Native Overlay Diff: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
 Volume: local
 Network: bridge host macvlan null overlay
 Log: awslogs fluentd gcplogs gelf journald json-file logentries splunk syslog
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 773c489c9c1b21a6d78b5c538cd395416ec50f88
runc version: 4fc53a81fb7c994640722ac585fa9ca548971871
init version: 949e6fa
Security Options:
 apparmor
 seccomp
  Profile: default
Kernel Version: 4.4.0-124-generic
Operating System: Ubuntu 16.04.4 LTS
OSType: linux
Architecture: x86_64
CPUs: 16
Total Memory: 15.66GiB
Name: allbak
ID: WDR7:SQTX:YHIB:2UCU:EY4X:RFST:INQY:EBGT:HO7M:4WFU:XXBI:YXSW
Docker Root Dir:

docker默认位置/var/lib/docker

以下是修改步骤:

1.停止docker

root@ubuntu:~# /etc/init.d/docker stop

2.迁移Docker路径  

root@ubuntu:~# cd /var/lib/
root@ubuntu:~# mv docker /media/sdj1/

3.建立软连接

ln -s /media/sdj1/docker docker

4.启动docker

root@ubuntu:~# /etc/init.d/docker start

5.docker info 再次查看信息

root@ubuntu:/var/lib/docker# docker info             
Containers: 2
 Running: 0
 Paused: 0
 Stopped: 2
Images: 39
Server Version: 18.05.0-ce
Storage Driver: overlay2
 Backing Filesystem: extfs
 Supports d_type: true
 Native Overlay Diff: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
 Volume: local
 Network: bridge host macvlan null overlay
 Log: awslogs fluentd gcplogs gelf journald json-file logentries splunk syslog
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 773c489c9c1b21a6d78b5c538cd395416ec50f88
runc version: 4fc53a81fb7c994640722ac585fa9ca548971871
init version: 949e6fa
Security Options:
 apparmor
 seccomp
  Profile: default
Kernel Version: 4.4.0-124-generic
Operating System: Ubuntu 16.04.4 LTS
OSType: linux
Architecture: x86_64
CPUs: 16
Total Memory: 15.66GiB
Name: allbak
ID: WDR7:SQTX:YHIB:2UCU:EY4X:RFST:INQY:EBGT:HO7M:4WFU:XXBI:YXSW
Docker Root Dir: /media/sdj1/docker