1. 环境准备
systemctl stop firewalld && systemctl disable firewalld # 关闭/禁用防火墙 setenforce 0 # 临时关闭 SELinux sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config # 永久关闭 SELinux
2. Docker 安装
yum install -y yum-utils device-mapper-persistent-data lvm2 # 安装依赖 yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo # 添加阿里源 sed -i 's+download.docker.com+mirrors.aliyun.com/docker-ce+' /etc/yum.repos.d/docker-ce.repo # 修改 repo 源地址 yum makecache fast # 更新缓存 yum list docker-ce.x86_64 --showduplicates | sort -r # 查看 Docker 版本 yum install -y docker-ce-19.03.11 # 选择一个版本安装, 这里我选择19.03
3. 配置 Docker 镜像加速器
# 如果没有这个目录需要先创建
mkdir -p /etc/docker
# 创建编写 daemon.json 文件 cat > /etc/docker/daemon.json <<EOF { "exec-opts": ["native.cgroupdriver=systemd"], "log-driver": "json-file", "log-opts": { "max-size": "100m" }, "storage-driver": "overlay2", "live-restore": true, "registry-mirrors": ["https://docker.mirrors.ustc.edu.cn/","https://hub-mirror.c.163.com","https://nszujuwm.mirror.aliyuncs.com"] } EOF
4. 启动 Docker
systemctl start docker && systemctl enable docker # 启动并添加开机自启 docker info # 查看 Docker 配置信息 /var/lib/docker # Docker 安装目录 ******** /var/log/message # Docker 日志信息 ******** docker version # 查看 Docker 版本 docker run hello-world # 启动第一个容器 --- Hello-World
5. 注册 Dockerhub 账号
hub.docker.com # Dockerhub网址 docker login docker.io # 注册好账号后登录 [root@docker ~]# docker login docker.io Login with your Docker ID to push and pull images from Docker Hub. If you don't have a Docker ID, head over to https://hub.docker.com to create one. Username: # 输入你注册的Docker hub账号密码 Password: WARNING! Your password will be stored unencrypted in /root/.docker/config.json. # 账号信息存放在 /root/.docker/config.json中, 可用base64解出密文 Configure a credential helper to remove this warning. See https://docs.docker.com/engine/reference/commandline/login/#credentials-store Login Succeeded