1、查看系统要求
docker 要求 centos 系统的内核版本高于 3.10 ,查看centos的内核版本。
uname -a
2、删除旧版本
yum remove docker docker-common docker-selinux docker-engine
3、安装需要的软件包
yum-util 提供yum-config-manager功能,另外两个是devicemapper驱动依赖的
sudo yum install -y yum-utils device-mapper-persistent-data lvm2
4、设置docker yum源
# 使用官方源 sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo # 使用阿里源 sudo yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo sudo sed -i 's+download.docker.com+mirrors.aliyun.com/docker-ce+' /etc/yum.repos.d/docker-ce.repo
5、查看所有仓库中所有docker版本
可以查看所有仓库中所有docker版本,并选择特定的版本安装。
yum list docker-ce --showduplicates | sort -r
6、安装docker
sh
sudo yum install docker-ce
由于repo中默认只开启stable仓库,故这里安装的是最新稳18.03.0.ce-1.el7.centos。
如果要安装特定版本:
sudo yum install docker-ce-18.06.1.ce
7、启动
设置为开机启动
systemctl enable docker
启动
systemctl start docker
查看启动状态
systemctl status docker
如果出现异常
$ systemctl start docker a dependency job for docker.service failed. see 'journalctl -xe' for details.
查看报错信息
mar 03 11:19:47 master1 systemd[1]: starting containerd container runtime... -- subject: unit containerd.service has begun start-up -- defined-by: systemd -- support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel -- -- unit containerd.service has begun starting up. mar 03 11:19:47 master1 systemd[104332]: failed at step limits spawning /sbin/modprobe: operation not permitted -- subject: process /sbin/modprobe could not be executed -- defined-by: systemd -- support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel -- -- the process /sbin/modprobe could not be executed and failed. -- -- the error number returned by this process is 1. mar 03 11:19:47 master1 systemd[104335]: failed at step limits spawning /usr/bin/containerd: operation not permitted -- subject: process /usr/bin/containerd could not be executed -- defined-by: systemd -- support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel -- -- the process /usr/bin/containerd could not be executed and failed.
解决方案:
查看open files的值,修改/usr/lib/systemd/system/docker.service和/usr/lib/systemd/system/containerd.service(如下图),启动即可
$ ulimit -a core file size (blocks, -c) 0 data seg size (kbytes, -d) unlimited scheduling priority (-e) 0 file size (blocks, -f) unlimited pending signals (-i) 23056 max locked memory (kbytes, -l) 64 max memory size (kbytes, -m) unlimited open files (-n) 654350 pipe size (512 bytes, -p) 8 posix message queues (bytes, -q) 819200 real-time priority (-r) 0 stack size (kbytes, -s) 8192 cpu time (seconds, -t) unlimited max user processes (-u) 23056 virtual memory (kbytes, -v) unlimited file locks (-x) unlimited
$ vim /usr/lib/systemd/system/docker.service ... # having non-zero limit*s causes performance problems due to accounting overhead # in the kernel. we recommend using cgroups to do container-local accounting. limitnofile=654349 # 注意这里 limitnproc=23057 limitcore=infinity # comment tasksmax if your systemd version does not supports it. ...
$ vim /usr/lib/systemd/system/containerd.service ... # having non-zero limit*s causes performance problems due to accounting overhead # in the kernel. we recommend using cgroups to do container-local accounting. limitnofile=654349 # 注意这里 limitnproc=23057 limitcore=infinity # comment tasksmax if your systemd version does not support it. ...
查看版本
docker version
8、修改数据目录
方式一
# 将下面的json拷贝纸docker启动目录 $ vim /etc/docker/daemon.json { "data-root": "/data/docker" }
方式二
查看docker当前信息
$ docker info client: context: default debug mode: false plugins: app: docker app (docker inc., v0.9.1-beta3) buildx: docker buildx (docker inc., v0.8.2-docker) scan: docker scan (docker inc., v0.17.0) server: containers: 40 running: 15 paused: 0 stopped: 25 images: 91 server version: 20.10.17 storage driver: overlay2 backing filesystem: extfs supports d_type: true native overlay diff: true userxattr: false logging driver: json-file cgroup driver: systemd cgroup version: 1 plugins: volume: local network: bridge host ipvlan macvlan null overlay log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog swarm: inactive runtimes: io.containerd.runc.v2 io.containerd.runtime.v1.linux runc default runtime: runc init binary: docker-init containerd version: 10c12954828e7c7c9b6e0ea9b0c02b01407d3ae1 runc version: v1.1.2-0-ga916309f init version: de40ad0 security options: seccomp profile: default kernel version: 3.10.0-1160.71.1.el7.x86_64 operating system: centos linux 7 (core) ostype: linux architecture: x86_64 cpus: 16 total memory: 15.5gib name: master1 id: 3wqc:qctb:i5d4:2zwl:vbsh:6gwq:4w2g:btk2:xsey:pdxg:bqai:zb6d docker root dir: /data/docker # 这里是数据目录的位置,我因为已经更改过,原位置为/var/lib/docker debug mode: false registry: https://index.docker.io/v1/ labels: experimental: false insecure registries: 127.0.0.0/8 registry mirrors: https://x6u7jv2l.mirror.aliyuncs.com/ live restore enabled: false
9、停止docker服务
$ systemctl stop docker
10、修改docker服务启动文件
vi /usr/lib/systemd/system/docker.service execstart=/usr/bin/dockerd -h fd:// --containerd=/run/containerd/containerd.sock --graph=/data/docker
11、复制原有数据,若无数据,可跳过此步骤
$ cp -rf /var/lib/docker/* /data/docker/
12、重新加载配置文件并启动
$ systemctl daemon-reload $ systemctl start docker
最后执行步骤8,查看是否已启动
到此这篇关于docker 安装、升级、修改数据目录的操作方法的文章就介绍到这了,更多相关docker 修改数据目录内容请搜索代码网以前的文章或继续浏览下面的相关文章希望大家以后多多支持代码网!
发表评论