Docker学习(1) Linux安装dockers

Linux安装dockers

1、查看版本信息是否符合安装条件:

  • 用户使用linux为64位操作系统;
  • 系统内核版本至少在3.10以上。
[root@wangliukun ~]# uname -a
Linux wangliukun 6.5.6 #1 SMP PREEMPT_DYNAMIC Tue Oct 10 09:17:13 EDT 2023 x86_64 x86_64 x86_64 GNU/Linux
[root@wangliukun ~]# uname -r
6.5.6

2、yum更新

使用Root权限登录 Centos。确保yum包更新到最新。

[root@wangliukun ~]# yum update

3、卸载原有docker

[root@wangliukun ~]# yum remove docker \
                  docker-client \
                  docker-client-latest \
                  docker-common \
                  docker-latest \
                  docker-latest-logrotate \
                  docker-logrotate \
                  docker-engine

4、安装docker(使用阿里云yum安装)

  • 安装必要工具:
[root@wangliukun ~]# yum install -y yum-utils device-mapper-persistent-data lvm2
已安装:
  yum-utils.noarch 0:1.1.31-54.el7_8                                                   

作为依赖被安装:
  python-kitchen.noarch 0:1.1.1-5.el7                                                  

完毕!
  • 添加软件源信息
[root@wangliukun ~]# yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

遇到问题:

This system is not registered with an entitlement server. You can use subscription-manager to register.

原因:

Red Hat Subscription Manager订阅管理器,它会让你一直register

解决方法: 禁用就好。

[root@wangliukun ~]#vi /etc/yum/pluginconf.d/subscription-manager.conf

[main]
enabled=0

重新添加软件源信息即可

  • 换阿里镜像源
[root@wangliukun ~]# sed -i 's+download.docker.com+mirrors.aliyun.com/docker-ce+' /etc/yum.repos.d/docker-ce.repo
  • 更新并安装docker-CE
[root@wangliukun ~]# yum makecache fast
[root@wangliukun ~]# yum -y install docker-ce

已安装:
  docker-ce.x86_64 3:25.0.3-1.el7                                                      

作为依赖被安装:
  containerd.io.x86_64 0:1.6.28-3.1.el7                                                
  docker-buildx-plugin.x86_64 0:0.12.1-1.el7                                           
  docker-ce-cli.x86_64 1:25.0.3-1.el7                                                  
  docker-ce-rootless-extras.x86_64 0:25.0.3-1.el7                                      
  docker-compose-plugin.x86_64 0:2.24.6-1.el7                                          

完毕!

  • 开启docker服务设置开机自启
[root@wangliukun ~]# start docker.service
[root@wangliukun ~]# systemctl enable docker
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.
  • 安装校验
[root@wangliukun ~]# docker version
Client: Docker Engine - Community
 Version:           25.0.3
 API version:       1.44
 Go version:        go1.21.6
 Git commit:        4debf41
 Built:             Tue Feb  6 21:17:10 2024
 OS/Arch:           linux/amd64
 Context:           default

Server: Docker Engine - Community
 Engine:
  Version:          25.0.3
  API version:      1.44 (minimum version 1.24)
  Go version:       go1.21.6
  Git commit:       f417435
  Built:            Tue Feb  6 21:16:08 2024
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.6.28
  GitCommit:        ae07eda36dd25f8a1b98dfbf587313b99c0190bb
 runc:
  Version:          1.1.12
  GitCommit:        v1.1.12-0-g51d5e94
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0
[root@wangliukun ~]# 
  • 下载hello-world
[root@wangliukun ~]# docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
c1ec31eb5944: Pull complete 
Digest: sha256:d000bc569937abbe195e20322a0bde6b2922d805332fd6d8a68b19f524b7d21d
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/
  • 配置docker加速器(阿里云)
  • 可能出现问题:无法拉取hello-world

  • [root@wangliukun ~]# docker run hello-world
    Unable to find image 'hello-world:latest' locally
    Trying to pull repository docker.io/library/hello-world ... 
    /usr/bin/docker-current: missing signature key.
    See '/usr/bin/docker-current run --help'.
    

意思是docker在本地没有找到hello-world镜像,也没有从docker仓库中拉取到镜像。

​ 意思是docker在本地没有找到hello-world镜像,也没有从docker仓库中拉取到镜像。

  • 异常原因:

​ 这是因为docker服务器在国外,基于网速与“和谐墙”的问题,所以我们在国内操作国外镜像可能无法正常拉取,这需要我们为docker设置国内的阿里云镜像加速器。

  • 解决方法:

1、登录阿里云 - 容器 Hub 服务控制台后,点击“镜像加速器”标签,找到镜像工具–>镜像加速

2、根据手册配置文件,添加阿里云镜像:

[root@wangliukun ~]#vi /etc/docker/daemon.json

 { 
 "registry-mirrors": ["https://v97vyodn.mirror.aliyuncs.com"] 
 }
 
 #systemctl restart docker
 #sudo systemctl status docker

3、重新拉取即可成功
下一章:Docker镜像

  • 5
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
要在Linux安装Docker,可以按照以下步骤进行操作: 1. 首先,确保你的Linux系统满足Docker安装要求。Docker要求使用64位的Linux系统,并且内核版本至少为3.10以上。你可以通过运行以下命令来检查你的系统内核版本: ``` uname -r ``` 2. 在安装Docker之前,建议先更新系统软件包。使用以下命令更新软件包列表: ``` sudo apt update ``` 3. 安装Docker的依赖包。运行以下命令安装所需的依赖包: ``` sudo apt install apt-transport-https ca-certificates curl software-properties-common ``` 4. 添加Docker的官方GPG密钥。运行以下命令导入Docker官方GPG密钥: ``` curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg ``` 5. 添加Docker的软件源。根据你的Linux发行版,选择运行以下命令中的一个。 对于Ubuntu 20.04: ``` echo "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null ``` 对于Ubuntu 18.04: ``` echo "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu bionic stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null ``` 6. 更新软件包列表。使用以下命令更新软件包列表以包含Docker软件源: ``` sudo apt update ``` 7. 安装Docker引擎。运行以下命令安装Docker引擎: ``` sudo apt install docker-ce docker-ce-cli containerd.io ``` 8. 验证Docker安装是否成功。运行以下命令检查Docker版本: ``` docker --version ``` 如果安装成功,将会显示Docker的版本信息。 现在你已经成功在Linux安装Docker。你可以使用`docker`命令来管理和运行容器了。记得在使用`docker`命令时,需要使用`sudo`或将当前用户添加到`docker`用户组中。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值