美文网首页
02_Docker安装

02_Docker安装

作者: 单v纯微笑 | 来源:发表于2021-04-30 16:02 被阅读0次

    参考资料

    环境准备

    Linux CentOS 8

    uname -r # 查看内核版本,需要在3.10+
    4.18.0-193.6.3.el8_2.x86_64
    

    yum 配置阿里云源(非必须)

    # 备份
    mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
    # 下载新的CentOS-Base.repo
    wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-8.repo
    # 生成缓存
    yum clean all
    yum makecache
    

    安装

    需要在root用户下进行

    自动安装(CentOS7推荐)

    • 使用官方安装脚本自动安装,CentOS8会报错
    curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun
    
    • 可能报错
    package docker-ce-3:19.03.2-3.el7.x86_64 requires containerd.io >= 1.2.2-3, but none of the providers can be installed
    - cannot install the best candidate for the job
    - package containerd.io-1.2.2-3.3.el7.x86_64 is excluded
    - package containerd.io-1.2.2-3.el7.x86_64 is excluded
    - package containerd.io-1.2.4-3.1.el7.x86_64 is excluded
    - package containerd.io-1.2.5-3.1.el7.x86_64 is excluded
    - package containerd.io-1.2.6-3.3.el7.x86_64 is excluded
    (try to add '--skip-broken' to skip uninstallable packages or '--nobest' to use not only best candidate packages)
    
    • 报错解决
    1. 要么就降低Docker 的版本

    2. 如果不想降低Docker 版本,那么就更新 containerd.io 的版本

    # 下载
    wget https://download.docker.com/linux/centos/7/x86_64/edge/Packages/containerd.io-1.2.6-3.3.el7.x86_64.rpm
    # 安装
    yum install -y  containerd.io-1.2.6-3.3.el7.x86_64.rpm
    

    手动安装(CentOS8推荐)

    1. 卸载旧版本
    yum remove docker \
                      docker-client \
                      docker-client-latest \
                      docker-common \
                      docker-latest \
                      docker-latest-logrotate \
                      docker-logrotate \
                      docker-engine
    
    1. 设置存储库
    # 安装yum-utils软件包(提供yum-config-manager 实用程序)
    yum install -y yum-utils
    # 设置稳定的存储库。
    # 如果配置了yum为阿里云源,那么这一步应该就不需要
    yum-config-manager \
        --add-repo \
        http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
    
    1. 安装Docker引擎
    yum install docker-ce docker-ce-cli containerd.io
    

    启动停止重启

    启动
    systemctl start docker
    
    停止
    systemctl stop docker
    
    重启
    systemctl restart docker
    

    测试

    • 运行容器
    docker run hello-world
    
    • 打印如下日志说明正常
    # 日志内容
    Unable to find image 'hello-world:latest' locally # 没有找到镜像
    latest: Pulling from library/hello-world # 从远程仓库中拉取
    0e03bdcc26d7: Pull complete # 拉取成功
    Digest: sha256:49a1c8800c94df04e9658809b006fd8a686cab8028d33cfba2cc049724254202
    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/
    

    相关文章

      网友评论

          本文标题:02_Docker安装

          本文链接:https://www.haomeiwen.com/subject/hppwrltx.html