CentOS 安装docker教程

第一步执行 sudo yum install -y yum-utils 安装工具包

执行后报错:admin is not in the sudoers file. This incident will be reported.

解决办法:

1>、进入超级用户模式。也就是输入"su -",系统会让你输入超级用户密码,输入密码后就进入了超级用户模式。

  
2>、添加文件的写权限。也就是输入命令"chmod u+w /etc/sudoers"3>、编辑/etc/sudoers文件。也就是输入命令"vim /etc/sudoers",输入"i"进入编辑模式,
找到这一行:"root ALL=(ALL) ALL"在起下面添加"xxx ALL=(ALL) ALL"(这里的xxx是你的用户名),
 
然后保存(就是先摁一下Esc键,然后输入":wq")退出。
    
4>、撤销文件的写权限。也就是输入命令"chmod u-w /etc/sudoers"。
至此,问题解决。

执行后再次报错 Failed to download metadata for repo ‘AppStream’

执行命令出现下面错误“错误:Failed to download metadata for repo ‘AppStream’

 查询后发现问题的原因是Centos8于2021年年底停止了服务,我们在使用yum源安装时候,出现下面错误“错误:Failed to download metadata for repo ‘AppStream’: Cannot prepare internal mirrorlist: No URLs in mirrorlist”。

解决办法:

1. 进入yum的repos目录:  

cd /etc/yum.repos.d/
2. 修改所有的CentOS文件内容:

  分别输入已下2行命令:

sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-*
sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-*
3. 测试是否可以yum安装:

sudo yum install -y yum-utils 
没在报错,顺利安装成功。

执行命令 sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo

第二步执行 sudo yum install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin 安装docker插件

第三步执行 sudo systemctl start docker 启动docker

第四部执行 sudo docker run hello-world 验证daoker是否安装成功

执行后报错 Unable to find image 'hello-world:latest' locally

     latest: Pulling from library/hello-world
                  c1ec31eb5944: Pull complete

解决方案

//1)在/etc/docker文件夹下执行:
sudo touch daemon.json

//2)修改/etc/docker/daemon.json 文件权限
chmod 777 daemon.json

//3)daemon.json文件中写入如下内容:
------------------
{ 
"registry-mirrors": ["https://alzgoonw.mirror.aliyuncs.com"] 
}

  //重启docker
  systemctl restart docker


  //查看状态
  systemctl status docker

 

  docker run hello-world


 

 

安装完毕

参考地址: https://docs.docker.com/engine/install/centos/#installation-methods

                   https://www.cnblogs.com/nthforsth/articles/12257755.html

        https://www.cnblogs.com/harbin1900/p/17028829.html

        https://www.cnblogs.com/dingjiaoyang/p/7268739.html

posted @ 2024-01-26 10:49  Fast & Furious  阅读(195)  评论(0)    收藏  举报