Docker配置
daemon.json配置项说明dockerd:https://docs.docker.com/engine/reference/commandline/dockerd/
学习推荐 哔哩哔哩 狂神说java
https://blog.csdn.net/weixin_43831049/article/details/106184345
https://www.cnblogs.com/wyt007/p/11154156.html#
一、修改docker的数据目录
1.查看docker安装时的默认数据目录 find / -name docker
/etc/docker #配置 /sys/fs/cgroup/hugetlb/docker /sys/fs/cgroup/blkio/docker /sys/fs/cgroup/devices/docker /sys/fs/cgroup/perf_event/docker /sys/fs/cgroup/net_cls,net_prio/docker /sys/fs/cgroup/memory/docker /sys/fs/cgroup/pids/docker /sys/fs/cgroup/cpu,cpuacct/docker /sys/fs/cgroup/freezer/docker /sys/fs/cgroup/cpuset/docker /sys/fs/cgroup/systemd/docker /run/docker /usr/share/bash-completion/completions/docker /usr/bin/docker /usr/libexec/docker /var/lib/docker #docke数据目录 /var/lib/docker/overlay2/11bbb66131f25bf1bf9ea31d001668730bcf6052bf5c92c124cc0fedbf0663d5/diff/etc/dpkg/dpkg.cfg.d/docker
2.在/etc/docker目录下创建daemon.json文件并添加配置
vim /etc/docker/daemon.json
{ "data-root":"/data/docker" #docker的数据库目录 }
3.拷贝原数据目录下的所有文件到新的目录,并删除原来目录的数据,重新启动docker服务
cp -r /var/lib/docker/* /data/docker/ rm -rf /var/lib/docker #先停止docker: systemctl stop docker
systemctl start docker
4.使用 docker info 查看数据目录是否切换成功
docker info
Total Memory: 3.683GiB Name: localhost.localdomain ID: 44KR:4G3I:FELO:OKEJ:KFCH:U7IJ:UEPF:YIRP:QWU2:HWJW:SJ7W:4PJ2 Docker Root Dir: /data/docker Debug Mode: false Registry: https://index.docker.io/v1/
二、镜像加速
1.在/etc/docker目录下创建daemon.json文件追加配置
{ "data-root":"/data/docker", #docker的数据库目录 "registry-mirrors": ["https://z3y3z5ic.mirror.aliyuncs.com"] #镜像加速 }
2.重启docker服务: systemctl restart docker
三、开启debug
1.在/etc/docker目录下创建daemon.json文件追加配置
{
"data-root":"/data/docker", #docker的数据库目录
"registry-mirrors": ["https://z3y3z5ic.mirror.aliyuncs.com"], #镜像加速
}
2.重启docker服务: systemctl restart docker
3.查看日志
journalctl 统一查看service所有的日志。
journalctl -u docker.service -f
四、远程连接docker deamon
1.修改docker.service启动信息
# 修改docker.service启动信息
vim /usr/lib/systemd/system/docker.service
# ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock ExecStart=/usr/bin/dockerd --containerd=/run/containerd/containerd.sock
2.修改daemon.json
#修改daemon.json vim /etc/docker/daemon.json { "registry-mirrors": ["https://uwxsp1y1.mirror.aliyuncs.com"], "data-root": "/data/docker", "debug":true, "hosts": ["192.168.103.240:6381","unix:///var/run/docker.sock"] }
3.重载、重启
# 重载、重启 sudo systemctl daemon-reload service docker restart
4.查看端口
# 查看端口 netstat -tlnp [root@localhost docker]# netstat -tlnp Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 192.168.103.240:6381 0.0.0.0:* LISTEN 27825/dockerd tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 1/systemd tcp 0 0 192.168.122.1:53 0.0.0.0:* LISTEN 3743/dnsmasq tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 3122/sshd tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 3109/cupsd tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 3479/master tcp 0 0 127.0.0.1:6010 0.0.0.0:* LISTEN 14503/sshd: root@pt tcp6 0 0 :::111 :::* LISTEN 1/systemd tcp6 0 0 :::22 :::* LISTEN 3122/sshd tcp6 0 0 ::1:631 :::* LISTEN 3109/cupsd tcp6 0 0 ::1:25 :::* LISTEN 3479/master tcp6 0 0 ::1:6010 :::* LISTEN 14503/sshd: root@pt
5.# 远程连接测试
docker -H 192.168.103.240:6381 ps