文章已同步至掘金:https://juejin.cn/post/7210944562222383160
欢迎访问😃,有任何问题都可留言评论哦~
官方文档地址:https://docs.docker.com/engine/install/centos/
- 卸载旧版本docker(如果之前没有装过docker可以忽略) {#1.-%E5%8D%B8%E8%BD%BD%E6%97%A7%E7%89%88%E6%9C%ACdocker(%E5%A6%82%E6%9E%9C%E4%B9%8B%E5%89%8D%E6%B2%A1%E6%9C%89%E8%A3%85%E8%BF%87docker%E5%8F%AF%E4%BB%A5%E5%BF%BD%E7%95%A5)} ================================================================================================================================================================================================================
yum remove docker docker-common docker-selinux
-
安装 yum-utils 包 {#2.-%E5%AE%89%E8%A3%85-yum-utils-%E5%8C%85} ==================================================================
更新 yum 包 生产环境中此步操作需慎重,看自己情况,学习的话随便搞 这个命令不是必须执行的,看个人情况,后面出现不兼容的情况的话就必须update了
yum -y update
sudo yum install -y yum-utils device-mapper-persistent-data lvm2
- 配置稳定仓库(二选一,有其他稳定仓库可以自行配置) {#3.-%E9%85%8D%E7%BD%AE%E7%A8%B3%E5%AE%9A%E4%BB%93%E5%BA%93%EF%BC%88%E4%BA%8C%E9%80%89%E4%B8%80%EF%BC%8C%E6%9C%89%E5%85%B6%E4%BB%96%E7%A8%B3%E5%AE%9A%E4%BB%93%E5%BA%93%E5%8F%AF%E4%BB%A5%E8%87%AA%E8%A1%8C%E9%85%8D%E7%BD%AE%EF%BC%89} ====================================================================================================================================================================================================================================================================
- 配置国内稳定仓库
yum-config-manager --add-repo <https://download.docker.com/linux/centos/docker-ce.repo
>
- 配置阿里源仓库
sudo yum-config-manager --add-repo <http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
>
- 更新一下yum缓存 {#4.-%E6%9B%B4%E6%96%B0%E4%B8%80%E4%B8%8Byum%E7%BC%93%E5%AD%98} ============================================================================
sudo yum makecache fast
- 安装docker {#5.-%E5%AE%89%E8%A3%85docker} ==========================================
yum install docker-ce
- 验证是否安装成功 {#6.-%E9%AA%8C%E8%AF%81%E6%98%AF%E5%90%A6%E5%AE%89%E8%A3%85%E6%88%90%E5%8A%9F} ==========================================================================================
docker version
-
设置开机启动 {#7.-%E8%AE%BE%E7%BD%AE%E5%BC%80%E6%9C%BA%E5%90%AF%E5%8A%A8} ======================================================================
systemctl start docker ## 启动
systemctl status docker ## 查看状态
systemctl enable docker ## 开机自启动
- 设置docker国内镜像源(也可不设置,但是官方镜像源国内有时候可能拉不到) {#8.-%E8%AE%BE%E7%BD%AEdocker%E5%9B%BD%E5%86%85%E9%95%9C%E5%83%8F%E6%BA%90%EF%BC%88%E4%B9%9F%E5%8F%AF%E4%B8%8D%E8%AE%BE%E7%BD%AE%EF%BC%8C%E4%BD%86%E6%98%AF%E5%AE%98%E6%96%B9%E9%95%9C%E5%83%8F%E6%BA%90%E5%9B%BD%E5%86%85%E6%9C%89%E6%97%B6%E5%80%99%E5%8F%AF%E8%83%BD%E6%8B%89%E4%B8%8D%E5%88%B0%EF%BC%89} ======================================================================================================================================================================================================================================================================================================================================================
8.1 国内的镜像地址 {#8.1-%E5%9B%BD%E5%86%85%E7%9A%84%E9%95%9C%E5%83%8F%E5%9C%B0%E5%9D%80}
8.1.1 docker中国区官方镜像 {#8.1.1-docker%E4%B8%AD%E5%9B%BD%E5%8C%BA%E5%AE%98%E6%96%B9%E9%95%9C%E5%83%8F}
<https://registry.docker-cn.com>
8.1.2 网易 {#8.1.2-%E7%BD%91%E6%98%93}
<http://hub-mirror.c.163.com>
8.1.3 中国科学技术大学 {#8.1.3-%E4%B8%AD%E5%9B%BD%E7%A7%91%E5%AD%A6%E6%8A%80%E6%9C%AF%E5%A4%A7%E5%AD%A6}
<https://docker.mirrors.ustc.edu>.
8.2 修改daemon.json文件 {#8.2-%E4%BF%AE%E6%94%B9daemon.json%E6%96%87%E4%BB%B6}
8.2.1 创建或者修改 /ect/docker/daemon.json文件 {#8.2.1-%E5%88%9B%E5%BB%BA%E6%88%96%E8%80%85%E4%BF%AE%E6%94%B9-%2Fect%2Fdocker%2Fdaemon.json%E6%96%87%E4%BB%B6}
vim /etc/docker/daemon.json
8.2.2 添加或者修改如下内容 {#8.2.2-%E6%B7%BB%E5%8A%A0%E6%88%96%E8%80%85%E4%BF%AE%E6%94%B9%E5%A6%82%E4%B8%8B%E5%86%85%E5%AE%B9}
{
"registry-mirrors": ["<https://registry.docker-cn.com>"]
}
8.3 重启docker服务 {#8.3-%E9%87%8D%E5%90%AFdocker%E6%9C%8D%E5%8A%A1}
systemctl restart docker
8.4 查看源配置是否成功 {#8.4-%E6%9F%A5%E7%9C%8B%E6%BA%90%E9%85%8D%E7%BD%AE%E6%98%AF%E5%90%A6%E6%88%90%E5%8A%9F}
执行docker info
查看字段:Registry Mirrors
- 安装docker-compose编排器 {#9.-%E5%AE%89%E8%A3%85docker-compose%E7%BC%96%E6%8E%92%E5%99%A8} ========================================================================================
9.1 安装docker-compose {#9.1-%E5%AE%89%E8%A3%85docker-compose}
- 官方地址(速度emmm,可能会很慢)
执行sudo curl -L "<https://github.com/docker/compose/releases/download/1.24.1/docker-compose-$>(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
9.2 赋予执行权限 {#9.2-%E8%B5%8B%E4%BA%88%E6%89%A7%E8%A1%8C%E6%9D%83%E9%99%90}
sudo chmod +x /usr/local/bin/docker-compose
9.3 创建软链接 {#9.3-%E5%88%9B%E5%BB%BA%E8%BD%AF%E9%93%BE%E6%8E%A5}
ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
9.4 验证docker-compose是否安装成功 {#9.4-%E9%AA%8C%E8%AF%81docker-compose%E6%98%AF%E5%90%A6%E5%AE%89%E8%A3%85%E6%88%90%E5%8A%9F}
执行docker-compose -version