卸载旧版本
卸载后保留/var/lib/docker的内容(镜像、容器、存储卷和网络等)
故需指令删除干净
rm -rf /var/lib/docker
$ sudo yum install -y yum-utils #安装工具包,缺少这些依赖将无法完成
执行结果
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
sudo yum install docker-ce
$ sudo systemctl start docker
或者
$ sudo service docker start
$ service docker start #启动docker
$ chkconfig docker on #加入开机启动
sudo docker version
sudo docker run hello-world
执行结果: (注意一下,结果没那么快出来)
安装包官方地址:https://download.docker.com/linux/static/stable/x86_64/
可以下载到本地,通过ftp等工具上传到服务器上,或者在服务器上使用wget命令下载,若没有安装wget可以使用yum安装,将安装压缩文件保存至自定义的目录下
wget https://download.docker.com/linux/static/stable/x86_64/docker-18.06.3-ce.tgz
2.1准备docker.service文件
[Unit] Description=Docker Application Container Engine Documentation=https://docs.docker.com After=network-online.target firewalld.service Wants=network-online.target [Service] Type=notify # the default is not to use systemd for cgroups because the delegate issues still # exists and systemd currently does not support the cgroup feature set required # for containers run by docker ExecStart=/usr/bin/dockerd --selinux-enabled=false --insecure-registry=127.0.0.1 ExecReload=/bin/kill -s HUP $MAINPID # 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=infinity LimitNPROC=infinity LimitCORE=infinity # Uncomment TasksMax if your systemd version supports it. # Only systemd 226 and above support this version. #TasksMax=infinity TimeoutStartSec=0 # set delegate yes so that systemd does not reset the cgroups of docker containers Delegate=yes # kill only the docker process, not all processes in the cgroup KillMode=process # restart the docker process if it exits prematurely Restart=on-failure StartLimitBurst=3 StartLimitInterval=60s [Install] WantedBy=multi-user.target
2.2准备安装脚本文件installDocker.sh
#!/bin/sh echo ‘解压tar包...‘ tar -xvf $1 echo ‘将docker目录移到/usr/bin目录下...‘ cp docker/* /usr/bin/ echo ‘将docker.service 移到/lib/systemd/system/目录...‘
cp docker.service /lib/systemd/system/
echo ‘添加文件权限...‘
chmod +x /lib/systemd/system/docker.service
echo ‘重新加载配置文件...‘
systemctl daemon-reload
echo ‘启动docker...‘
systemctl start docker
echo ‘设置开机自启...‘
systemctl enable docker.service
echo ‘docker安装成功...‘
docker -v
2.3准备卸载脚本文件uninstallDocker.sh
#!/bin/sh echo ‘删除docker.service...‘ rm -f /lib/systemd/system/docker.service echo ‘删除docker文件...‘ rm -rf /usr/bin/docker* echo ‘重新加载配置文件‘ systemctl daemon-reload echo ‘卸载成功...‘
准备文件工作完毕,此时文件路径下有这些文件
编写完后赋予脚本执行权限,然后执行脚本即可
安装:
卸载:
注:
1.此处的--insecure-registry=127.0.0.1(此处改成你私服ip)设置是针对有搭建了自己私服Harbor时允许docker进行不安全的访问,否则访问将会被拒绝。
2.安装脚本中的重新加载配置文件(每次有修改docker.service文件时都要重新加载下)指令
systemctl daemon-reload???????
3.由于国内外网络问题,可以配置镜像加速地址
跳转到/etc/docker路径下,编写daemon.json文件,使用阿里云的镜像(此处个人使用申请个阿里云账号,不同账户的阿里云加速路径地址不一致)
{ "registry-mirrors": ["https://lnfy1vx5.mirror.aliyuncs.com"] }
docker的一般是使用
# 检查镜像 $ docker search xxx #查看当前镜像 $ docker images # 安装镜像 $ docker pull xxx #根据镜像启动容器 $ docker run -it --name container-name -d image-name:tag-name #(-d 表示后台运行) eg: $ docker run --name my_tomcat tomcat:latest # 查看哪些容器 $ docker ps -a # 查看哪些镜像正在运行 $ docker ps # 启动容器 $ docker start container-id # 打开容器 docker exec -it container-id /bin/bash # 停止容器 $ docker stop container-name # 删除容器 $ docker rm container-id $ docker rmi image-name
参考:https://blog.csdn.net/laughing1997/article/details/84305615
和https://blog.csdn.net/xibei19921101/article/details/108340982
安装私服仓库:https://www.cnblogs.com/naixin007/p/10952813.html
原文:https://www.cnblogs.com/liaoyanglong/p/13821565.html