Ubuntu安装Docker

在 Linux ,在终端上运行以下命令验证内核以及架构详细信息:正如上面你看到的那样,我的 Ubuntu 系统内核版本是 5.15.0-101并且系统架构是 64 位(x86_64 x86_64 x86_64 GNU/Linux)

wcx@wcx-Ubuntu:~/Desktop$ uname -a
Linux wcx-Ubuntu 5.15.0-101-generic #111~20.04.1-Ubuntu SMP Mon Mar 11 15:44:43 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux

1:更新你的 Ubuntu 系统。
sudo apt update

wcx@wcx-Ubuntu:~/Desktop$ sudo apt update
[sudo] password for wcx: 
Hit:1 http://mirrors.tuna.tsinghua.edu.cn/ubuntu focal InRelease                                                    
Hit:3 http://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-updates InRelease                                            
Hit:4 http://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-backports InRelease                                          
Hit:2 https://packages.microsoft.com/repos/code stable InRelease                                                    
Hit:5 http://security.ubuntu.com/ubuntu focal-security InRelease                                                    
Hit:6 http://lenovo.archive.canonical.com focal InRelease
Reading package lists... Done
Building dependency tree       
Reading state information... Done
14 packages can be upgraded. Run 'apt list --upgradable' to see them.

sudo apt upgrade

wcx@wcx-Ubuntu:~/Desktop$ sudo apt upgrade
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Calculating upgrade... Done
Get more security updates through Ubuntu Pro with 'esm-apps' enabled:
  libavformat58 liburiparser1 libswresample3 libhdf5-103 libavformat-dev
  libswresample-dev libavutil-dev libavcodec-dev libpmix2 libavcodec58
  libavutil56 libswscale5 libopenexr24 libhdf5-openmpi-103 libswscale-dev
Learn more about Ubuntu Pro at https://ubuntu.com/pro
The following NEW packages will be installed:
  ubuntu-pro-client
The following packages will be upgraded:
  code libgpgme11 libgpgmepp6 python3-update-manager snapd tracker-extract tracker-miner-fs ubuntu-advantage-tools
  ubuntu-drivers-common ubuntu-pro-client-l10n update-manager update-manager-core update-notifier
  update-notifier-common
14 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 126 MB of archives.
After this operation, 69.1 MB disk space will be freed.
Do you want to continue? [Y/n] Y
Get:2 http://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-updates/main amd64 ubuntu-drivers-common amd64 1:0.9.0~0.20.04.8 [53.6 kB]
Get:1 https://packages.microsoft.com/repos/code stable/main amd64 code amd64 1.87.2-1709912201 [99.9 MB]
Get:3 http://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-updates/main amd64 update-manager all 1:20.04.10.20 [552 kB]
Get:4 http://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-updates/main amd64 update-manager-core all 1:20.04.10.20 [11.6 kB]
Get:5 http://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-updates/main amd64 python3-update-manager all 1:20.04.10.20 [38.4 kB]
Get:6 http://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-updates/main amd64 ubuntu-advantage-tools all 31.2~20.04 [10.9 kB]
Get:7 http://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-updates/main amd64 ubuntu-pro-client amd64 31.2~20.04 [196 kB]
Get:8 http://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-updates/main amd64 update-notifier amd64 3.192.30.19 [56.0 kB]
Get:9 http://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-updates/main amd64 update-notifier-common all 3.192.30.19 [173 kB]
Get:10 http://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-updates/main amd64 ubuntu-pro-client-l10n amd64 31.2~20.04 [18.4 kB]
Get:11 http://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-updates/main amd64 libgpgme11 amd64 1.13.1-7ubuntu2.2 [120 kB]
Get:12 http://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-updates/main amd64 libgpgmepp6 amd64 1.13.1-7ubuntu2.2 [101 kB]
Get:13 http://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-updates/main amd64 snapd amd64 2.61.3+20.04 [24.4 MB]
Get:14 http://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-updates/main amd64 tracker-miner-fs amd64 2.3.3-2ubuntu0.20.04.2 [68.2 kB]
Get:15 http://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-updates/main amd64 tracker-extract amd64 2.3.3-2ubuntu0.20.04.2 [278 kB]
Fetched 126 MB in 22s (5,789 kB/s)                                                                                  
Preconfiguring packages ...
(Reading database ... 225121 files and directories currently installed.)
Preparing to unpack .../00-ubuntu-drivers-common_1%3a0.9.0~0.20.04.8_amd64.deb ...
Unpacking ubuntu-drivers-common (1:0.9.0~0.20.04.8) over (1:0.9.0~0.20.04.7) ...
Preparing to unpack .../01-update-manager_1%3a20.04.10.20_all.deb ...
Unpacking update-manager (1:20.04.10.20) over (1:20.04.10.18) ...
Preparing to unpack .../02-update-manager-core_1%3a20.04.10.20_all.deb ...
Unpacking update-manager-core (1:20.04.10.20) over (1:20.04.10.18) ...
Preparing to unpack .../03-python3-update-manager_1%3a20.04.10.20_all.deb ...
Unpacking python3-update-manager (1:20.04.10.20) over (1:20.04.10.18) ...
Preparing to unpack .../04-ubuntu-advantage-tools_31.2~20.04_all.deb ...
Unpacking ubuntu-advantage-tools (31.2~20.04) over (30~20.04) ...
dpkg: warning: unable to delete old directory '/var/lib/ubuntu-advantage': Directory not empty
dpkg: warning: unable to delete old directory '/etc/ubuntu-advantage': Directory not empty
Selecting previously unselected package ubuntu-pro-client.
Preparing to unpack .../05-ubuntu-pro-client_31.2~20.04_amd64.deb ...
Unpacking ubuntu-pro-client (31.2~20.04) ...
Preparing to unpack .../06-update-notifier_3.192.30.19_amd64.deb ...
Unpacking update-notifier (3.192.30.19) over (3.192.30.17) ...
Preparing to unpack .../07-update-notifier-common_3.192.30.19_all.deb ...
Unpacking update-notifier-common (3.192.30.19) over (3.192.30.17) ...
Preparing to unpack .../08-ubuntu-pro-client-l10n_31.2~20.04_amd64.deb ...
Unpacking ubuntu-pro-client-l10n (31.2~20.04) over (30~20.04) ...
Preparing to unpack .../09-code_1.87.2-1709912201_amd64.deb ...
Unpacking code (1.87.2-1709912201) over (1.86.2-1707854558) ...
Preparing to unpack .../10-libgpgme11_1.13.1-7ubuntu2.2_amd64.deb ...
Unpacking libgpgme11:amd64 (1.13.1-7ubuntu2.2) over (1.13.1-7ubuntu2.1) ...
Preparing to unpack .../11-libgpgmepp6_1.13.1-7ubuntu2.2_amd64.deb ...
Unpacking libgpgmepp6:amd64 (1.13.1-7ubuntu2.2) over (1.13.1-7ubuntu2.1) ...
Preparing to unpack .../12-snapd_2.61.3+20.04_amd64.deb ...
Unpacking snapd (2.61.3+20.04) over (2.58+20.04.1) ...
Preparing to unpack .../13-tracker-miner-fs_2.3.3-2ubuntu0.20.04.2_amd64.deb ...
Unpacking tracker-miner-fs (2.3.3-2ubuntu0.20.04.2) over (2.3.3-2ubuntu0.20.04.1) ...
Preparing to unpack .../14-tracker-extract_2.3.3-2ubuntu0.20.04.2_amd64.deb ...
Unpacking tracker-extract (2.3.3-2ubuntu0.20.04.2) over (2.3.3-2ubuntu0.20.04.1) ...
Progress: [ 49%] [##############################################.................................................] 
Setting up snapd (2.61.3+20.04) ...#############################.................................................] 
Installing new version of config file /etc/apparmor.d/usr.lib.snapd.snap-confine.real ...
snapd.failure.service is a disabled or a static unit not running, not starting it.
snapd.snap-repair.service is a disabled or a static unit not running, not starting it.
Failed to restart snapd.mounts-pre.target: Operation refused, unit snapd.mounts-pre.target may be requested by depend
ency only (it is configured to refuse manual start/stop).
See system logs and 'systemctl status snapd.mounts-pre.target' for details.
Setting up ubuntu-drivers-common (1:0.9.0~0.20.04.8) ...
Setting up tracker-extract (2.3.3-2ubuntu0.20.04.2) ...
Setting up libgpgme11:amd64 (1.13.1-7ubuntu2.2) ...
Setting up python3-update-manager (1:20.04.10.20) ...
Setting up ubuntu-pro-client (31.2~20.04) ...
Setting up ubuntu-pro-client-l10n (31.2~20.04) ...
Setting up libgpgmepp6:amd64 (1.13.1-7ubuntu2.2) ...
Setting up ubuntu-advantage-tools (31.2~20.04) ...
Setting up update-manager-core (1:20.04.10.20) ...
Setting up update-notifier-common (3.192.30.19) ...
Setting up update-manager (1:20.04.10.20) ...
Processing triggers for man-db (2.9.1-1) ...
Processing triggers for dbus (1.12.16-2ubuntu2.3) ...
Processing triggers for shared-mime-info (1.15-1) ...
Processing triggers for desktop-file-utils (0.24-1ubuntu3) ...
Processing triggers for mime-support (3.64ubuntu1) ...
Processing triggers for hicolor-icon-theme (0.17-2) ...
Processing triggers for gnome-menus (3.36.0-1ubuntu1) ...
Processing triggers for libglib2.0-0:amd64 (2.64.6-1~ubuntu20.04.6) ...
Processing triggers for libc-bin (2.31-0ubuntu9.14) ...
Setting up tracker-miner-fs (2.3.3-2ubuntu0.20.04.2) ...
Installing new version of config file /etc/xdg/autostart/tracker-miner-fs.desktop ...
Created symlink /etc/systemd/user/gnome-session.target.wants/tracker-miner-fs.service → /usr/lib/systemd/user/tracker
-miner-fs.service.
Setting up update-notifier (3.192.30.19) ...

sudo apt full-upgrade

wcx@wcx-Ubuntu:~/Desktop$ sudo apt full-upgrade
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Calculating upgrade... Done
Get more security updates through Ubuntu Pro with 'esm-apps' enabled:
  libavformat58 liburiparser1 libswresample3 libhdf5-103 libavformat-dev
  libswresample-dev libavutil-dev libavcodec-dev libpmix2 libavcodec58
  libavutil56 libswscale5 libopenexr24 libhdf5-openmpi-103 libswscale-dev
Learn more about Ubuntu Pro at https://ubuntu.com/pro
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

2:添加 Docker 库
首先,安装必要的证书并允许 apt 包管理器使用以下命令通过 HTTPS 使用存储库:
sudo apt install apt-transport-https ca-certificates curl software-properties-common gnupg lsb-release

wcx@wcx-Ubuntu:~/Desktop$ sudo apt install apt-transport-https ca-certificates curl software-properties-common gnupg lsb-release
Reading package lists... Done
Building dependency tree       
Reading state information... Done
lsb-release is already the newest version (11.1.0ubuntu2).
lsb-release set to manually installed.
ca-certificates is already the newest version (20230311ubuntu0.20.04.1).
curl is already the newest version (7.68.0-1ubuntu2.22).
gnupg is already the newest version (2.2.19-3ubuntu2.2).
gnupg set to manually installed.
software-properties-common is already the newest version (0.99.9.12).
apt-transport-https is already the newest version (2.0.10).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

然后,运行下列命令添加 Docker 的官方 GPG 密钥:

wcx@wcx-Ubuntu:~/Desktop$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg

添加 Docker 官方库:
wcx@wcx-Ubuntu:~/Desktop$ echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

使用命令更新 Ubuntu 源列表:
wcx@wcx-Ubuntu:~/Desktop$ sudo apt update
Get:1 https://download.docker.com/linux/ubuntu focal InRelease [57.7 kB]
Get:3 https://download.docker.com/linux/ubuntu focal/stable amd64 Packages [40.1 kB]                                
Hit:4 http://security.ubuntu.com/ubuntu focal-security InRelease                                                    
Hit:5 http://lenovo.archive.canonical.com focal InRelease                                                  
Hit:2 https://packages.microsoft.com/repos/code stable InRelease                                       
Hit:6 http://mirrors.tuna.tsinghua.edu.cn/ubuntu focal InRelease
Hit:7 http://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-updates InRelease
Hit:8 http://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-backports InRelease
Fetched 97.8 kB in 4s (21.9 kB/s)
Reading package lists... Done
Building dependency tree       
Reading state information... Done
All packages are up to date.

3:安装 Docker

sudo apt install docker-ce docker-ce-cli containerd.io docker-compose-plugin

wcx@wcx-Ubuntu:~/Desktop$ sudo apt install docker-ce docker-ce-cli containerd.io docker-compose-plugin
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following additional packages will be installed:
  docker-buildx-plugin docker-ce-rootless-extras pigz slirp4netns
Suggested packages:
  aufs-tools cgroupfs-mount | cgroup-lite
The following NEW packages will be installed:
  containerd.io docker-buildx-plugin docker-ce docker-ce-cli docker-ce-rootless-extras docker-compose-plugin pigz
  slirp4netns
0 upgraded, 8 newly installed, 0 to remove and 0 not upgraded.
Need to get 120 MB of archives.
After this operation, 428 MB of additional disk space will be used.
Do you want to continue? [Y/n] Y
Get:1 https://download.docker.com/linux/ubuntu focal/stable amd64 containerd.io amd64 1.6.28-2 [29.7 MB]
Get:4 https://download.docker.com/linux/ubuntu focal/stable amd64 docker-buildx-plugin amd64 0.13.1-1~ubuntu.20.04~focal [29.5 MB]
Get:5 https://download.docker.com/linux/ubuntu focal/stable amd64 docker-ce-cli amd64 5:26.0.0-1~ubuntu.20.04~focal [13.8 MB]
Get:6 https://download.docker.com/linux/ubuntu focal/stable amd64 docker-ce amd64 5:26.0.0-1~ubuntu.20.04~focal [25.1 MB]
Get:2 http://mirrors.tuna.tsinghua.edu.cn/ubuntu focal/universe amd64 pigz amd64 2.4-1 [57.4 kB]                    
Get:3 http://mirrors.tuna.tsinghua.edu.cn/ubuntu focal/universe amd64 slirp4netns amd64 0.4.3-1 [74.3 kB]           
Get:7 https://download.docker.com/linux/ubuntu focal/stable amd64 docker-ce-rootless-extras amd64 5:26.0.0-1~ubuntu.20.04~focal [9,328 kB]
Get:8 https://download.docker.com/linux/ubuntu focal/stable amd64 docker-compose-plugin amd64 2.25.0-1~ubuntu.20.04~focal [12.1 MB]
Fetched 120 MB in 12s (9,905 kB/s)                                                                                  
Selecting previously unselected package pigz.
(Reading database ... 225126 files and directories currently installed.)
Preparing to unpack .../0-pigz_2.4-1_amd64.deb ...
Unpacking pigz (2.4-1) ...
Selecting previously unselected package containerd.io.
Preparing to unpack .../1-containerd.io_1.6.28-2_amd64.deb ...
Unpacking containerd.io (1.6.28-2) ...
Selecting previously unselected package docker-buildx-plugin.
Preparing to unpack .../2-docker-buildx-plugin_0.13.1-1~ubuntu.20.04~focal_amd64.deb ...
Unpacking docker-buildx-plugin (0.13.1-1~ubuntu.20.04~focal) ...
Selecting previously unselected package docker-ce-cli.
Preparing to unpack .../3-docker-ce-cli_5%3a26.0.0-1~ubuntu.20.04~focal_amd64.deb ...
Unpacking docker-ce-cli (5:26.0.0-1~ubuntu.20.04~focal) ...
Selecting previously unselected package docker-ce.
Preparing to unpack .../4-docker-ce_5%3a26.0.0-1~ubuntu.20.04~focal_amd64.deb ...
Unpacking docker-ce (5:26.0.0-1~ubuntu.20.04~focal) ...
Selecting previously unselected package docker-ce-rootless-extras.
Preparing to unpack .../5-docker-ce-rootless-extras_5%3a26.0.0-1~ubuntu.20.04~focal_amd64.deb ...
Unpacking docker-ce-rootless-extras (5:26.0.0-1~ubuntu.20.04~focal) ...
Selecting previously unselected package docker-compose-plugin.
Preparing to unpack .../6-docker-compose-plugin_2.25.0-1~ubuntu.20.04~focal_amd64.deb ...
Unpacking docker-compose-plugin (2.25.0-1~ubuntu.20.04~focal) ...
Selecting previously unselected package slirp4netns.
Preparing to unpack .../7-slirp4netns_0.4.3-1_amd64.deb ...
Unpacking slirp4netns (0.4.3-1) ...
Setting up slirp4netns (0.4.3-1) ...
Setting up docker-buildx-plugin (0.13.1-1~ubuntu.20.04~focal) ...
Setting up containerd.io (1.6.28-2) ...
Created symlink /etc/systemd/system/multi-user.target.wants/containerd.service → /lib/systemd/system/containerd.servi
ce.
Setting up docker-compose-plugin (2.25.0-1~ubuntu.20.04~focal) ...
Setting up docker-ce-cli (5:26.0.0-1~ubuntu.20.04~focal) ...
Setting up pigz (2.4-1) ...
Setting up docker-ce-rootless-extras (5:26.0.0-1~ubuntu.20.04~focal) ...
Setting up docker-ce (5:26.0.0-1~ubuntu.20.04~focal) ...
Created symlink /etc/systemd/system/multi-user.target.wants/docker.service → /lib/systemd/system/docker.service.
Created symlink /etc/systemd/system/sockets.target.wants/docker.socket → /lib/systemd/system/docker.socket.
Processing triggers for man-db (2.9.1-1) ...
Processing triggers for systemd (245.4-4ubuntu3.23) ...

查看已安装的 Docker 版本:
sudo docker version

wcx@wcx-Ubuntu:~/Desktop$ sudo docker version
Client: Docker Engine - Community
 Version:           26.0.0
 API version:       1.45
 Go version:        go1.21.8
 Git commit:        2ae903e
 Built:             Wed Mar 20 15:17:51 2024
 OS/Arch:           linux/amd64
 Context:           default

Server: Docker Engine - Community
 Engine:
  Version:          26.0.0
  API version:      1.45 (minimum version 1.24)
  Go version:       go1.21.8
  Git commit:       8b79278
  Built:            Wed Mar 20 15:17:51 2024
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.6.28
  GitCommit:        ae07eda36dd25f8a1b98dfbf587313b99c0190bb
 runc:
  Version:          1.1.12
  GitCommit:        v1.1.12-0-g51d5e94
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

安装完成后,运行如下命令验证 Docker 服务是否在运行:
systemctl status docker

wcx@wcx-Ubuntu:~/Desktop$ systemctl status docker
● docker.service - Docker Application Container Engine
     Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
     Active: active (running) since Fri 2024-03-29 15:12:18 CST; 2min 45s ago
TriggeredBy: ● docker.socket
       Docs: https://docs.docker.com
   Main PID: 231894 (dockerd)
      Tasks: 22
     Memory: 31.4M
     CGroup: /system.slice/docker.service
             └─231894 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock

329 15:12:04 wcx-Ubuntu systemd[1]: Starting Docker Application Container Engine...
329 15:12:04 wcx-Ubuntu dockerd[231894]: time="2024-03-29T15:12:04.141158804+08:00" level=info msg="Starting up"
329 15:12:04 wcx-Ubuntu dockerd[231894]: time="2024-03-29T15:12:04.141660590+08:00" level=info msg="detected 127.>
329 15:12:08 wcx-Ubuntu dockerd[231894]: time="2024-03-29T15:12:08.750367831+08:00" level=info msg="Loading conta>
329 15:12:12 wcx-Ubuntu dockerd[231894]: time="2024-03-29T15:12:12.334171856+08:00" level=info msg="Loading conta>
329 15:12:13 wcx-Ubuntu dockerd[231894]: time="2024-03-29T15:12:13.152996605+08:00" level=info msg="Docker daemon>
329 15:12:13 wcx-Ubuntu dockerd[231894]: time="2024-03-29T15:12:13.153094108+08:00" level=info msg="Daemon has co>
329 15:12:18 wcx-Ubuntu dockerd[231894]: time="2024-03-29T15:12:18.322585977+08:00" level=info msg="API listen on>
329 15:12:18 wcx-Ubuntu systemd[1]: Started Docker Application Container Engine.

[1]+  Stopped                 systemctl status docker

验证Docker安装:
要验证Docker是否正确安装,您可以运行一个简单的测试容器。执行以下命令:
sudo docker run hello-world

wcx@wcx-Ubuntu:~/Desktop$ sudo docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
c1ec31eb5944: Pull complete 
Digest: sha256:53641cd209a4fecfc68e21a99871ce8c6920b2e7502df0a20671c6fccc73a7c6
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/
  • 2
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值