美文网首页
Docker 安装

Docker 安装

作者: 吉他手_c156 | 来源:发表于2020-12-13 23:36 被阅读0次

Docker 官网 docker.com

Centos 安装

卸载旧版本`
$ sudo yum remove docker \
                  docker-client \
                  docker-client-latest \
                  docker-common \
                  docker-latest \
                  docker-latest-logrotate \
                  docker-logrotate \
                  docker-engine
安装必要依赖
$ sudo yum install -y yum-utils
设置 docker 仓库
$ sudo yum-config-manager \
    --add-repo \
    https://download.docker.com/linux/centos/docker-ce.repo
安装 docker

最新版

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

安装指定版本

  • 要安装特定版本的Docker Engine,请在存储库中列出可用版本,然后选择并安装
  • 列出并排序您存储库中可用的版本。此示例按版本号(从高到低)对结果进行排序
yum list docker-ce --showduplicates | sort -r

docker-ce.x86_64  3:18.09.1-3.el7                     docker-ce-stable
docker-ce.x86_64  3:18.09.0-3.el7                     docker-ce-stable
docker-ce.x86_64  18.06.1.ce-3.el7                    docker-ce-stable
docker-ce.x86_64  18.06.0.ce-3.el7                    docker-ce-stable
......

返回的列表取决于启用的存储库,并且特定于您的CentOS版本(.el7在此示例中以后缀表示)。

b。通过其完全合格的软件包名称安装特定版本,该软件包名称是软件包名称(docker-ce)加上版本字符串(第二列),从第一个冒号(:)一直到第一个连字符,并用连字符(-)分隔。例如,docker-ce-18.09.1。

sudo yum install docker-ce-<VERSION_STRING> docker-ce-cli-<VERSION_STRING> containerd.io
卸载 docker
  • 卸载Docker Engine,CLI和Containerd软件包:
sudo yum remove docker-ce docker-ce-cli containerd.io
  • 主机上的映像,容器,卷或自定义配置文件不会自动删除。要删除所有图像,容器和卷
sudo rm -rf /var/lib/docker

ubuntu 安装

前提条件
操作系统要求

要安装Docker Engine,您需要以下Ubuntu版本之一的64位版本:

  • Ubuntu Groovy 20.10
  • Ubuntu Focal 20.04(LTS)
  • Ubuntu Bionic 18.04(LTS)
  • Ubuntu Xenial 16.04(LTS)

Docker Engine在x86_64(或amd64armhf,和arm64体系结构上受支持。

卸载旧版本

泊坞窗的旧版本被称为dockerdocker.iodocker-engine。如果已安装,请卸载它们:

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

使用存储库安装

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

  • 设置存储库
    更新apt软件包索引并安装软件包以允许apt通过HTTPS使用存储库:
$ sudo apt-get update

$ sudo apt-get install \
    apt-transport-https \
    ca-certificates \
    curl \
    gnupg-agent \
    software-properties-common
  • 添加Docker的官方GPG密钥:
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
  • 9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88通过搜索指纹的后8个字符,验证您现在是否拥有带有指纹的密钥 。
$ sudo apt-key fingerprint 0EBFCD88

pub   rsa4096 2017-02-22 [SCEA]
      9DC8 5822 9FC7 DD38 854A  E2D8 8D81 803C 0EBF CD88
uid           [ unknown] Docker Release (CE deb) <docker@docker.com>
sub   rsa4096 2017-02-22 [S]
设置稳定版仓库
$ sudo add-apt-repository \
   "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
   $(lsb_release -cs) \
   stable"
安装DOCKER引擎
  • 更新apt软件包索引,并安装最新版本的Docker Engine和容器化的容器,或转到下一步以安装特定版本:
 $ sudo apt-get update
 $ sudo apt-get install docker-ce docker-ce-cli containerd.io
  • 要安装特定版本的Docker Engine,请在存储库中列出可用版本,然后选择并安装:
  1. 列出您的仓库中可用的版本:
$ apt-cache madison docker-ce

  docker-ce | 5:18.09.1~3-0~ubuntu-xenial | https://download.docker.com/linux/ubuntu  xenial/stable amd64 Packages
  docker-ce | 5:18.09.0~3-0~ubuntu-xenial | https://download.docker.com/linux/ubuntu  xenial/stable amd64 Packages
  docker-ce | 18.06.1~ce~3-0~ubuntu       | https://download.docker.com/linux/ubuntu  xenial/stable amd64 Packages
  docker-ce | 18.06.0~ce~3-0~ubuntu       | https://download.docker.com/linux/ubuntu  xenial/stable amd64 Packages
  ...
  1. 使用第二列中的版本字符串安装特定版本,例如5:18.09.13-0ubuntu-xenial。
$ sudo apt-get install docker-ce=<VERSION_STRING> docker-ce-cli=<VERSION_STRING> containerd.io

测试 Docker 是否安装成功,输入以下指令,打印出以下信息则安装成功:

$ sudo docker run hello-world

Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
1b930d010525: Pull complete                                                                                                                                  Digest: sha256:c3b4ada4687bbaa170745b3e4dd8ac3f194ca95b2d0518b417fb47e5879d9b5f
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
  • 卸载Docker Engine,CLI和Containerd软件包
$ sudo apt-get purge docker-ce docker-ce-cli containerd.io
  • 主机上的映像,容器,卷或自定义配置文件不会自动删除。要删除所有图像,容器和卷
$ sudo rm -rf /var/lib/docker

配置阿里云加速器

sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors":  ["https://docker.mirrors.ustc.edu.cn"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker

docker 操作

查看docker版本
sudo docker version
启动docker
sudo systemctl start docker
停止docker
sudo systemctl stop docker
重启docker
sudo systemctlrestart docker
查看docker状态
sudo systemctl status docker
开机启动:
sudo systemctl enable docker
image
查看docker概要信息
sudo docker info
查看docker帮助文档
sudo docker --help

相关文章

网友评论

      本文标题:Docker 安装

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