安装docker
1、卸载docker
查看是否有旧版本docker
docker info
首先检测我们虚拟机是否已经安装过Docker,如果安装则需卸载。代码中“\”符号为换行符,相当于一行内容分为多行,这是检测docker的各种组件
yum remove docker \docker-client \docker-client-latest \docker-common \docker-latest \docker-latest-logrotate \docker-logrotate \docker-selinux \docker-engine-selinux \docker-engine \docker-ce
2、安装docker
安装Docker需要将我们的计算机联网,安装yum工具
yum install -y yum-utils \device-mapper-persistent-data \lvm2 --skip-broken
更新本地镜像
# 设置docker镜像源
yum-config-manager \--add-repo \https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.reposed -i 's/download.docker.com/mirrors.aliyun.com\/docker-ce/g' /etc/yum.repos.d/docker-ce.repoyum makecache fast
输入docker安装命令
yum install -y docker-ce
3、启动docker
注意关闭防火墙
# 关闭
systemctl stop firewalld# 禁止开机启动防火墙
systemctl disable firewalld
通过命令启动和开机启动
systemctl start docker # 启动docker服务systemctl stop docker # 停止docker服务systemctl restart docker # 重启docker服务systemctl enable docker # 加入开机启动
查看docker版本
docker -v
说明docker安装成功
安装dockerCompose
1、下载安装好dockerCompose
方式一:通过命令下载:
# 安装
curl -L https://github.com/docker/compose/releases/download/1.23.1/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
如出现错误提示:
curl: (7) Failed connect to raw.githubusercontent.com:443; 拒绝连接
修改hosts文件
echo "199.232.68.133 raw.githubusercontent.com" >> /etc/hostsecho "185.199.111.133 raw.githubusercontent.com" >> /etc/hostsecho "185.199.108.133 raw.githubusercontent.com" >> /etc/hosts
方法二:
直接到https://github.com/docker/compose/releases 页面中 选择linux-x86_64到/usr/local/bin文件夹中改名docker-compose
2、修改文件权限
# 修改权限
chmod +x /usr/local/bin/docker-compose
Base自动补全命令:
# 补全命令
curl -L https://raw.githubusercontent.com/docker/compose/1.29.1/contrib/completion/bash/docker-compose > /etc/bash_completion.d/docker-compose