002.Docker安装部署
Posted itzgr
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了002.Docker安装部署相关的知识,希望对你有一定的参考价值。
一 docker安装-CentOS系统
1.1 docker自动安装脚本
1 [email protected]:~# wget -qO- https://get.docker.com/ | sh 2 或—— 3 [email protected]:~# curl -sSL https://get.docker.com/ | sh
注意:若出现以下错误,可使用yum解决依赖——
Delta RPMs disabled because /usr/bin/yum provides applydeltarpmnot installed.
1 yum provides applydeltarpm #查询缺少的applydeltarpm所在包 2 yum install libdevmapper* -y 3 yum -y install deltarpm #安装此包 4 yum install -y epel-release #有可能会依旧提示错误,安装此包即可 5 [email protected]:~# docker version #查询docker版本
1.2 docker yum安装
1 [email protected]:~# yum -y remove docker 2 docker-client 3 docker-client-latest 4 docker-common 5 docker-latest 6 docker-latest-logrotate 7 docker-logrotate 8 docker-selinux 9 docker-engine-selinux 10 docker-engine #若存在旧版需要全新安装可卸载旧版 11 [email protected]:~# yum -y update 12 [email protected]:~# yum install -y yum-utils 13 device-mapper-persistent-data 14 lvm2 15 [email protected]:~# yum-config-manager 16 --add-repo 17 https://download.docker.com/linux/centos/docker-ce.repo #配置docker源
提示:也可使用国内阿里云——
1 [email protected]:~# yum-config-manager 2 --add-repo 3 http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo 4 [email protected]:~# yum-config-manager --enable docker-ce-edge #开启源 5 [email protected]:~# yum-config-manager --enable docker-ce-test #开启源 6 [email protected]:~# yum -y install docker-ce #安装docker 7 [email protected]:~# yum -y install docker-registry #安装docker仓库 8 [email protected]:~# systemctl start docker.service 9 [email protected]:~# systemctl enable docker.service #设为开机启动
二 docker安装-Ubuntu系统
2.1 更新源数据库
1 [email protected]:~# apt-get remove docker docker-engine docker.io #卸载旧版 2 [email protected]:~# sudo apt-get update
2.2 安装软件包
1 [email protected]:~# sudo apt-get -y install 2 apt-transport-https 3 ca-certificates 4 curl 5 software-properties-common #安装软件包以允许apt通过HTTPS使用存储库
2.3 添加Docker的官方GPG密钥
1 [email protected]:~# curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
注意:也可添加阿里云GPG:
curl -fsSL https://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add -
2.4 验证秘钥指纹
1 [email protected]:~# sudo apt-key fingerprint 0EBFCD88
2.5 配置仓库并在此更新源
1 [email protected]:~# sudo add-apt-repository 2 "deb [arch=amd64] https://download.docker.com/linux/ubuntu 3 $(lsb_release -cs) 4 stable" 5 [email protected]:~# sudo apt-get update
注意:国内建议配置为阿里仓库,命令如下:
1 [email protected]:~# sudo add-apt-repository "deb [arch=amd64] https://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable" 2 [email protected]:~# sudo apt-get update
2.6 安装docker ce
1 [email protected]:~# sudo apt-get -y install docker-ce
2.7 测试并查看版本
1 [email protected]:~# sudo docker run hello-world 2 [email protected]:~# sudo docker version
注意:若存在旧版本可执行以下命令卸载旧版本——
apt-get remove docker docker-engine docker-common container-selinux docker-selinux
三 docker相关优化
3.1 配置docker加速器
1 [email protected]:~# mkdir -p /etc/docker 2 [email protected]:~# vim /etc/docker/daemon.json 3 { 4 "registry-mirrors": ["https://dbzucv6w.mirror.aliyuncs.com"] 5 } 6 [email protected]:~# cat /etc/docker/daemon.json 7 { 8 "registry-mirrors": ["https://dbzucv6w.mirror.aliyuncs.com"] 9 } 10 [email protected]:~# systemctl daemon-reload 11 [email protected]:~# systemctl restart docker 12 [email protected]:~# sudo systemctl enable docker
提示:docker通过https://hub.docker.com/搭建镜像共享生态系统,由于从国外拉取源比较慢,建议配置国内阿里加速器。
3.2 更改docker镜像路径
1 [email protected]:~# vi /usr/lib/systemd/system/docker.service 2 ExecStart=/usr/bin/dockerd-current --graph=/data/docker #仅需要追加新路径 3 [email protected]:~# systemctl daemon-reload 4 [email protected]:~# systemctl restart docker
以上是关于002.Docker安装部署的主要内容,如果未能解决你的问题,请参考以下文章