Docker使用手册-安装Docker

Docker

Docker 是一个开源的应用容器引擎,基于 Go 语言 并遵从 Apache2.0 协议开源。

Docker 可以让开发者打包他们的应用以及依赖包到一个轻量级、可移植的容器中,然后发布到任何流行的 Linux 机器上,也可以实现虚拟化。

容器是完全使用沙箱机制,相互之间不会有任何接口(类似 iPhone 的 app),更重要的是容器性能开销极低。

安装

本教程所有命令默认情况下在root中执行,如果不是root用户,请在命令前加sudo!

Ubuntu

更新apt依赖包:

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 -

搜索指纹并验证:

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]

设置稳定版仓库:

 add-apt-repository \
   "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
  $(lsb_release -cs) \
  stable"

更新apt包索引:

apt-get update

安装Docker-CE和containerd:

apt-get install docker-ce docker-ce-cli containerd.io

验证是否安装成功:

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已经安装成功了!

Centos7.x/8.x

安装依赖环境:

yum install -y yum-utils \
  device-mapper-persistent-data \
  lvm2

设置仓库:

yum-config-manager \
    --add-repo \
    https://download.docker.com/linux/centos/docker-ce.repo

安装Docker-CE:

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

测试是否安装成功:

docker run hello-world

如果出现和Ubuntu的教程中相同的输出则证明安装成功!

Last modification:November 4th, 2019 at 07:49 am
如果我的文章对你有用,请随意赞赏

One comment

  1. repostone

    非技术的路过。

Leave a Comment