docker笔记(二)之Ubuntu 安装 Docker

一、系统要求:

Docker 支持以下版本的 Ubuntu 操作系统:

  • Focal 20.04 (LTS)

  • Bionic 18.04 (LTS)

  • Xenial 16.04 (LTS)

Docker 可以安装在 64 位的 x86 平台或 ARM 平台上。Ubuntu 发行版中,LTS(Long-Term-Support)长期支持版本,会获得 5 年的升级维护支持,这样的版本会更稳定,因此在生产环境中推荐使用 LTS 版本。

二、安装

查看系统版本号:

 cat /etc/issue

卸载旧版本docker

apt-get remove docker \
               docker-engine \
               docker.io

由于 apt 源使用 HTTPS 以确保软件下载过程中不被篡改。因此,我们首先需要添加使用 HTTPS 传输的软件包以及 CA 证书。

apt-get update
apt-get install \
    apt-transport-https \
    ca-certificates \
    curl \
    gnupg-agent \
    software-properties-common

为了确认所下载软件包的合法性,需要添加软件源的 GPG 密钥。

curl -fsSL https://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add -

然后需要向 sources.list 中添加 Docker 软件源

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

注意:以上命令会添加稳定版本的 Docker APT 镜像源,如果需要测试版本的 Docker 请将 stable 改为 test。

扫描二维码关注公众号,回复: 14753057 查看本文章

更新 apt 软件包缓存,并安装 docker-ce

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

三、使用

启动docker

systemctl enable docker&&systemctl start docker

出于安全考虑,一般 Linux 系统上不会直接使用 root 用户使用docker。需要使用 docker 的用户加入 docker 用户组。

建立 docker 组:

test@test-virtual-machine:~$ sudo groupadd docker
groupadd:“docker”组已存在
test@test-virtual-machine:~$ sudo usermod -aG docker $USER
test@test-virtual-machine:~$ 
test@test-virtual-machine:~/桌面$ sudo gpasswd -a test docker  
正在将用户“test”加入到“docker”组中
#检测当前用户是否已经在docker用户组中

测试 Docker 是否安装正确

test@test-virtual-machine:~/桌面$ docker run hello-world

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/

参考链接:Ubuntu · Docker —— 从入门到实践 · 看云

猜你喜欢

转载自blog.csdn.net/WHQ556677/article/details/122292209