安装 docker bash 脚本用作 Azure VM 的自定义数据时不起作用

问题描述 投票:0回答:1

我使用此脚本在我的 Azure VM、操作系统 Debian Bullseye 11 上安装 docker:

echo "** Updating package lists..."
sudo apt update

echo "** Installing dependencies..."
sudo apt install -y apt-transport-https ca-certificates curl gnupg software-properties-common

echo "** Adding Docker GPG key..."
curl -fsSL https://download.docker.com/linux/debian/gpg | sudo apt-key add -

echo "** Adding Docker repository..."
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/debian bullseye stable" 

echo "** Updating package lists again..."
sudo apt update

echo "** Installing Docker..."
sudo apt install -y docker-ce

echo "** Docker installation complete!"

如果我手动运行此脚本(一次一行)它可以工作,但是当我将其用作自定义数据以便它在虚拟机初始化时执行时,它会给出错误,这是var/logs/cloud-init-输出.log:

    ** Updating package lists...

WARNING: apt does not have a stable CLI interface. Use with caution in scripts.

Reading package lists...
E: Could not get lock /var/lib/apt/lists/lock. It is held by process 700 (apt-get)
E: Unable to lock directory /var/lib/apt/lists/
** Installing dependencies...

WARNING: apt does not have a stable CLI interface. Use with caution in scripts.

Reading package lists...
Building dependency tree...
Reading state information...
Package gnupg 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 'gnupg' has no installation candidate
E: Unable to locate package software-properties-common
** Adding Docker GPG key...
E: gnupg, gnupg2 and gnupg1 do not seem to be installed, but one of them is required for this operation
(23) Failed writing body
** Adding Docker repository...
sudo: add-apt-repository: command not found
** Updating package lists again...

WARNING: apt does not have a stable CLI interface. Use with caution in scripts.

Reading package lists...
E: Could not get lock /var/lib/apt/lists/lock. It is held by process 700 (apt-get)
E: Unable to lock directory /var/lib/apt/lists/
** Installing Docker...

WARNING: apt does not have a stable CLI interface. Use with caution in scripts.

Reading package lists...
Building dependency tree...
Reading state information...
E: Unable to locate package docker-ce
** Docker installation complete!
bash azure azure-virtual-machine
1个回答
0
投票

问题似乎与安装

gnupg
有关。这很可能是因为 APT 包源烧录到映像中的存储库没有 gnupg1。你应该尝试:

  1. 在脚本行

    sudo apt install -y apt-transport-https ca-certificates curl gnupg software-properties-common
    中,将 gnupg 更改为 gnupg2

  2. 将 bullseye 主存储库添加到 APT 源。将以下行添加到脚本顶部:

# Add Debian APT package source
sudo sh -c 'echo "deb https://deb.debian.org/debian/ bullseye main" >> /etc/apt/sources.list'
sudo sh -c 'echo "deb-src https://deb.debian.org/debian/ bullseye main" >> /etc/apt/sources.list'

# Update sources
sudo apt update

仅当步骤 1 本身不起作用时才需要执行步骤 2。

© www.soinside.com 2019 - 2024. All rights reserved.