如何在Ubuntu 22.04上安装Docker和Docker Compose?

我按照指南中所说的做了一切,但我遇到了问题。
我使用的指南链接:https://docs.docker.com/desktop/install/ubuntu/

user@pc:~/Downloads$ sudo apt-get install docker-ce docker-ce-cli containerd.io docker-compose-plugin
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Package docker-ce is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source

Package docker-ce-cli is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source

E: Package 'docker-ce' has no installation candidate
E: Package 'docker-ce-cli' has no installation candidate
E: Unable to locate package containerd.io
E: Couldn't find any package by glob 'containerd.io'
E: Couldn't find any package by regex 'containerd.io'
E: Unable to locate package docker-compose-plugin

当我尝试安装依赖项时,出现了以下错误。
user@pc:~/Downloads$  sudo apt install lsb-release ca-certificates apt-transport-https software-properties-common -y
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
ca-certificates is already the newest version (20211016).
lsb-release is already the newest version (11.1.0ubuntu4).
software-properties-common is already the newest version (0.99.22.3).
software-properties-common set to manually installed.
You might want to run 'apt --fix-broken install' to correct these.
The following packages have unmet dependencies:
 docker-desktop : Depends: qemu-system-x86 (>= 5.2.0) but it is not going to be installed
                  Depends: docker-ce-cli but it is not installable
                  Depends: pass but it is not going to be installed
                  Depends: uidmap
E: Unmet dependencies. Try 'apt --fix-broken install' with no packages (or specify a solution).

当我安装docker时,会出现这个问题:
user@pc:~/Downloads$ 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


user@pc:~/Downloads$  sudo apt update
Hit:1 http://ua.archive.ubuntu.com/ubuntu jammy InRelease
Hit:2 http://ua.archive.ubuntu.com/ubuntu jammy-updates InRelease              
Hit:3 http://ua.archive.ubuntu.com/ubuntu jammy-backports InRelease            
Get:4 https://download.docker.com/linux/ubuntu jammy InRelease [48,9 kB]       
Get:5 http://dl.google.com/linux/chrome/deb stable InRelease [1 811 B]         
Get:6 http://security.ubuntu.com/ubuntu jammy-security InRelease [110 kB]      
Ign:7 https://ppa.launchpadcontent.net/rock-core/qt4/ubuntu jammy InRelease    
Hit:8 https://repo.skype.com/deb stable InRelease                              
Get:9 https://download.docker.com/linux/ubuntu jammy/stable amd64 Packages [6 255 B]
Err:5 http://dl.google.com/linux/chrome/deb stable InRelease                   
  The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 4EB27DB2A3B88B8B
Err:10 https://ppa.launchpadcontent.net/rock-core/qt4/ubuntu jammy Release     
  404  Not Found [IP: 185.125.190.52 443]
Ign:11 http://linux.dropbox.com/ubuntu disco InRelease                         
Get:12 http://linux.dropbox.com/ubuntu disco Release [6 598 B]
Get:13 http://security.ubuntu.com/ubuntu jammy-security/main amd64 DEP-11 Metadata [11,4 kB]
Get:14 http://security.ubuntu.com/ubuntu jammy-security/universe amd64 DEP-11 Metadata [10,1 kB]
Get:15 http://linux.dropbox.com/ubuntu disco Release.gpg [473 B]    
Get:16 http://linux.dropbox.com/ubuntu disco/main amd64 Packages [1 169 B]
Get:17 http://linux.dropbox.com/ubuntu disco/main i386 Packages [1 163 B]
Reading package lists... Done             
W: GPG error: http://dl.google.com/linux/chrome/deb stable InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 4EB27DB2A3B88B8B
E: The repository 'http://dl.google.com/linux/chrome/deb stable InRelease' is not signed.
N: Updating from such a repository can't be done securely, and is therefore disabled by default.
N: See apt-secure(8) manpage for repository creation and user configuration details.
E: The repository 'https://ppa.launchpadcontent.net/rock-core/qt4/ubuntu jammy Release' does not have a Release file.
N: Updating from such a repository can't be done securely, and is therefore disabled by default.
N: See apt-secure(8) manpage for repository creation and user configuration details.
W: https://repo.skype.com/deb/dists/stable/InRelease: Key is stored in legacy trusted.gpg keyring (/etc/apt/trusted.gpg), see the DEPRECATION section in apt-key(8) for details.
W: http://linux.dropbox.com/ubuntu/dists/disco/Release.gpg: Key is stored in legacy trusted.gpg keyring (/etc/apt/trusted.gpg), see the DEPRECATION section in apt-key(8) for details.


user@pc:~/Downloads$  sudo apt install docker-ce
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
You might want to run 'apt --fix-broken install' to correct these.
The following packages have unmet dependencies:
 docker-ce : Depends: containerd.io (>= 1.4.1) but it is not going to be installed
             Depends: docker-ce-cli but it is not going to be installed
             Recommends: docker-ce-rootless-extras but it is not going to be installed
             Recommends: pigz but it is not going to be installed
 docker-desktop : Depends: qemu-system-x86 (>= 5.2.0) but it is not going to be installed
                  Depends: docker-ce-cli but it is not going to be installed
                  Depends: pass but it is not going to be installed
                  Depends: uidmap
E: Unmet dependencies. Try 'apt --fix-broken install' with no packages (or specify a solution).

请帮帮我,我该怎么办!

我最后使用apt-get从默认仓库安装了Docker,官方网站和其他网站上的指南都是垃圾。 - mevsme
@kaerl 我知道如何使用apt和PPA。这并不能解决我的问题。我的问题是每个Ubuntu版本的工作方式都与以前的版本不同,整个Linux生态系统没有任何可靠性。因此,指南很快就过时了,但搜索结果并没有反映出这一点。 - mevsme
这个回答是否解决了你的问题? 如何在添加 PPA 后解决未满足的依赖关系? - karel
2个回答

这个问题是由Docker自己解答的,请查看页面 您可以手动安装插件
要下载并安装Compose CLI插件,请运行:
 DOCKER_CONFIG=${DOCKER_CONFIG:-$HOME/.docker}
 mkdir -p $DOCKER_CONFIG/cli-plugins
 curl -SL https://github.com/docker/compose/releases/download/v2.12.2/docker-compose-linux-x86_64 -o $DOCKER_CONFIG/cli-plugins/docker-compose

此命令将下载 Docker Compose 的最新版本(从 Compose releases 存储库),并将其安装到活动用户的 $HOME 目录下。

安装步骤如下:

要为系统上的所有用户安装 Docker Compose,请将 ~/.docker/cli-plugins 替换为 /usr/local/lib/docker/cli-plugins。 要使用不同版本的 Compose,请将 v2.12.2 替换为您想使用的 Compose 版本。 对二进制文件应用可执行权限:

 chmod +x $DOCKER_CONFIG/cli-plugins/docker-compose

或者,如果您选择为所有用户安装Compose:
 sudo chmod +x /usr/local/lib/docker/cli-plugins/docker-compose

测试安装。
 docker compose version

你可以试试:
sudo pip3 install docker-compose

这对我有帮助