Cent OS 7下安装Docker记录解决加载慢Unable to find image ‘hello-world:latest‘ locally等问题

一 更新yum包,排除系统环境干扰(不建议更新,直接从第二步开始!!!)

Cent OS 系统版本需要在7以上才可以安装Docker

//   不建议  直接从第二步开始!!!
yum update

二 安装所需的软件包

sudo yum install -y yum-utils device-mapper-persistent-data lvm2

三 设置镜像仓库

#官方给的镜像
###yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo

#建议使用阿里云的镜像进行加速,要不太慢了
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo 

四 安装 Docker Engine-Community

安装最新版本的 Docker Engine-Community 和 containerd,

sudo yum install docker-ce docker-ce-cli containerd.io

Cent OS 7下安装Docker记录解决加载慢Unable to find image ‘hello-world:latest‘ locally等问题_第1张图片

五 启动Docker

启动

sudo systemctl start docker

添加到开机启动

systemctl enable docker

六 验证是否启动成功

sudo docker run hello-world

如果成功将会出现下图字样
Cent OS 7下安装Docker记录解决加载慢Unable to find image ‘hello-world:latest‘ locally等问题_第2张图片
如果出现Unable to find image ‘hello-world:latest’ locally等字样,按如下步骤配置
在这里插入图片描述
1、修改/etc/docker/daemon.json 文件

cd /etc/docker
touch daemon.json
chmod 777 daemon.json
vi daemon.json

按i键进入编辑模式,输入

{ 
"registry-mirrors": ["https://alzgoonw.mirror.aliyuncs.com"] 
}

按ESC键,输入 :wq 保存并退出。

2.重启docker

//重启docker
systemctl restart docker

//查看状态
systemctl status docker

3运行hello-world镜像

docker run hello-world

问题完美解决。
至此,已经成功安装Docker了。

常用命令

----------------- docker ps 查看当前正在运行的容器

----------------- docker ps -a 查看所有容器的状态

----------------- docker start/stop id/name 启动/停止某个容器

----------------- docker attach id 进入某个容器(使用exit退出后容器也跟着停止运行)

----------------- docker exec -i -t id 启动一个伪终端以交互式的方式进入某个容器(使用exit退出后容器不停止运行)

----------------- docker images 查看本地镜像
----------------- docker rm id/name 删除某个容器
----------------- docker rmi id/name 删除某个镜像

docker run -d -p 8761:8761 eureka:1.0 运行docker 镜像
docker run -d -p 端口号:端口号 镜像名
----------------- docker run --name test -ti ubuntu /bin/bash 复制ubuntu容器并且重命名为test且运行,然后以伪终端交互式方式进入容器,运行bash

----------------- docker build -t soar/centos:7.1 . 通过当前目录下的Dockerfile创建一个名为soar/centos:7.1的镜像

----------------- docker run -d -p 80:8080 --name test soar/centos:7.1 以镜像soar/centos:7.1创建名为test的容器,并以后台模式运行,并做端口映射到宿主机80端口,P参数重启容器宿主机端口会发生改变 把本机的80端口映射到 容器的8080端口,访问时,只需要访问ip地址+本机端口即可

你可能感兴趣的:(CentOS服务器,docker,centos)