侧边栏壁纸
博主头像
如此肤浅

但行好事,莫问前程!

  • 累计撰写 52 篇文章
  • 累计创建 6 个标签
  • 累计收到 6 条评论

目 录CONTENT

文章目录

Docker | 安装

如此肤浅
2022-04-23 / 0 评论 / 0 点赞 / 58 阅读 / 1,853 字 / 正在检测是否收录...
温馨提示:
本文最后更新于 2022-05-15,若内容或图片失效,请留言反馈。部分素材来自网络,若不小心影响到您的利益,请联系我们删除。

转载自:如何在 Ubuntu 20.04 上安装和使用 Docker

环境:Ubuntu 20.04

安装

  1. 更新软件包索引,并且安装必要的依赖软件,来添加一个新的 HTTPS 软件源:
sudo apt update
sudo apt install apt-transport-https ca-certificates curl gnupg-agent software-properties-common
  1. 使用下面curl 导入源仓库的 GPG key:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
  1. 将 Docker APT 软件源添加到你的系统:
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"

现在,Docker 软件源被启用了,你可以安装软件源中任何可用的 Docker 版本。

  1. 安装 Docker 最新版本:
sudo apt update
sudo apt install docker-ce docker-ce-cli containerd.io

安装好后,默认只有 root 或有 sudo 权限的用户可以执行 Docker 命令。

  1. 一旦安装完成,Docker 服务将会自动启动。你可以输入下面的命令,验证它:
sudo systemctl status docker
  1. 输出将会类似下面这样:
● docker.service - Docker Application Container Engine
     Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
     Active: active (running) since Sat 2022-04-23 19:15:15 CST; 6min ago
......
  1. 验证 Docker 是否已经成功被安装:
sudo docker container run hello-world

如果本地没有该镜像,这个命令将会下载测试镜像,在容器中运行它,打印出 “Hello from Docker”,并且退出。

输出看起来应该像这样:

unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
2db29710123e: Pull complete 
Digest: sha256:10d7d58d5ebd2a652f4d93fdd86da8f265f5318c6a73cc5b6a9798ff6d2b2e67
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/
0

评论区