暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

Debian10安装Docker教程(国内源)

码上闯天下 2022-05-05
3365

Docker是一个容器化平台,允许您快速构建、测试和部署应用程序,作为便携式、自给自足的容器,几乎可以在任何地方运行。


在本教程中,将介绍如何在Debian 10 Buster上安装Docker。


卸载老版本:

旧版本的 Docker 被称为docker,docker.io或docker-engine. 如果安装了这些,请卸载它们:

    $ sudo apt-get remove docker docker-engine docker.io containerd runc

    如果apt-get提示没有安装这些软件包,那也没关系,代表您之前没有安装过它们。


    使用仓库安装方式安装

    在首次安装 Docker Engine 之前,您需要设置 Docker 存储库。之后,您可以从存储库安装和更新 Docker 了。

    设置存储库

    1. 更新apt包索引并安装通过HTTPS添加新存储库所需的软件包

       $ sudo apt-get update
      $ sudo apt-get install \
      ca-certificates \
      curl \
      gnupg \
      lsb-release

      2. 使用以下curl命令导入存储库的 GPG 密钥

        $ curl -fsSL http://mirrors.aliyun.com/docker-ce/linux/debian/gpg | sudo gpg --dearmor -o usr/share/keyrings/docker-archive-keyring.gpg

        3. 将稳定的 Docker APT 存储库添加到系统的软件存储库列表中

          $ echo \
          "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] http://mirrors.aliyun.com/docker-ce/linux/debian \
          $(lsb_release -cs) stable" | sudo tee etc/apt/sources.list.d/docker.list > dev/null
          # $(lsb_release -cs)将返回Debian发行版的名称。在这种情况下,就是这样buster。


          安装Docker Engine

          1. 更新apt包索引,安装最新版本的Docker Engine和containerd,或者进入下一步安装特定版本:

             $ sudo apt-get update
            $ sudo apt-get install docker-ce docker-ce-cli containerd.io

            2. 要安装特定版本的 Docker Engine,请在 repo 中列出可用版本,然后选择并安装:

              $ apt-cache madison docker-ce
              docker-ce | 5:20.10.14~3-0~debian-buster | http://mirrors.aliyun.com/docker-ce/linux/debian buster/stable amd64 Packages
              docker-ce | 5:20.10.13~3-0~debian-buster | http://mirrors.aliyun.com/docker-ce/linux/debian buster/stable amd64 Packages
               docker-ce | 5:20.10.12~3-0~debian-buster | http://mirrors.aliyun.com/docker-ce/linux/debian buster/stable amd64 Packages

              使用第二列中的版本字符串安装特定版本,例如: 5:20.10.14~3-0~debian-buster

                $ sudo apt-get install docker-ce=<VERSION_STRING> docker-ce-cli=<VERSION_STRING> containerd.io

                3. 设置 Docker 国内镜像源(中国科技大学

                  # 创建或修改 etc/docker/daemon.json 文件,修改为如下形式
                  {
                  "registry-mirrors" : [
                  "https://docker.mirrors.ustc.edu.cn"
                  ]
                  }


                  # 重启docker服务使配置生效
                  $ systemctl restart docker.service
                  # 查看是否配置成功
                  $ sudo docker info
                  Server:
                  ...
                   Registry Mirrors: #出现下列代表配置成功了!!!
                    https://docker.mirrors.ustc.edu.cn/


                  4. 通过运行`hello-world` 映像验证 Docker Engine 是否已正确安装

                    $ sudo docker run hello-world
                    Unable to find image 'hello-world:latest' locally
                    latest: Pulling from library/hello-world
                    2db29710123e: Pull complete
                    Digest: sha256:2498fce14358aa50ead0cc6c19990fc6ff866ce72aeb5546e1d59caac3d0d60f
                    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/



                    以非 root 用户身份管理 Docker

                    Docker 守护进程绑定到 Unix 套接字而不是 TCP 端口。默认情况下,Unix 套接字归root用户所有,其他用户只能借助sudo使用Docker 守护进程始终以root用户身份运行。


                    如果您不想在docker命令前加上sudo,请创建一个名为docker的用户组并向其中添加用户。当 Docker 守护进程启动时,它会创建一个可由docker组成员访问的 Unix 套接字

                      $ sudo groups                   #列出自己的用户组,确认自己在不在 docker 组中
                      $ sudo groupadd docker          #创建docker组,正常情况下安装好 Docker Engine 会自动创建一个docker用户组
                      $ sudo usermod -aG docker $USER #把当前用户加入到docker组中
                      $ newgrp docker #激活对组的更改
                      $ docker run hello-world        #验证是否可以不带sudo执行docker命令

                      到此,在Debian上安装 Docker 的教程已完成!



                      Docker 安装官方文档地址:

                      https://docs.docker.com/engine/install/debian


                      文章转载自码上闯天下,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

                      评论