使用 apt-key add 从文件添加密钥不起作用

Add key from file using apt-key add is not working

由于防火墙限制,我无法在 Dockerfile 中执行以下命令:

curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -

我所做的是手动下载 microsoft.asc,将其放置并 运行 我的 Dockerfile

中的以下内容
COPY myfolder/microsoft.asc /usr/
RUN apt-get update 
    && apt-get install -y curl apt-transport-https locales gnupg2 
    && /usr/microsoft.asc | apt-key add - 

这是我遇到的错误:

1: /usr/microsoft.asc: -----BEGIN: not found
2: /usr/microsoft.asc: mQENBFYxWIwBCADAKoZhZlJxGNGWzqV+1OG1xiQeoowKhssGAKvd+buXCGISZJwT: not found
3: /usr/microsoft.asc: LXZqIcIiLP7pqdcZWtE9bSc7yBY2MalDp9Liu0KekywQ6VVX1T72NPf5Ev6x6DLV: not found
4: /usr/microsoft.asc: 7aVWsCzUAF+eb7DC9fPuFLEdxmOEYoPjzrQ7cCnSV4JQxAqhU4T6OjbvRazGl3ag: not found
5: /usr/microsoft.asc: OeizPXmRljMtUUttHQZnRhtlzkmwIrUivbfFPD+fEoHJ1+uIdfOzZX8/oKHKLe2j: not found
6: /usr/microsoft.asc: H632kvsNzJFlROVvGLYAk2WRcLu+RjjggixhwiB+Mu/A8Tf4V6b+YppS44q8EvVr: not found
7: /usr/microsoft.asc: M+QvY7LNSOffSO6Slsy9oisGTdfE39nC7pVRABEBAAG0N01pY3Jvc29mdCAoUmVs: not found
8: /usr/microsoft.asc: ZWFzZSBzaWduaW5nKSA8Z3Bnc2VjdXJpdHlAbWljcm9zb2Z0LmNvbT6JATUEEwEC: not found
9: /usr/microsoft.asc: AB8FAlYxWIwCGwMGCwkIBwMCBBUCCAMDFgIBAh4BAheAAAoJEOs+lK2+EinPGpsH: not found
10: /usr/microsoft.asc: /32vKy29Hg51H9dfFJMx0/a/F+5vKeCeVqimvyTM04C+XENNuSbYZ3eRPHGHFLqe: not found
11: /usr/microsoft.asc: MNGxsfb7C7ZxEeW7J/vSzRgHxm7ZvESisUYRFq2sgkJ+HFERNrqfci45bdhmrUsy: not found
12: /usr/microsoft.asc: 7SWw9ybxdFOkuQoyKD3tBmiGfONQMlBaOMWdAsic965rvJsd5zYaZZFI1UwTkFXV: not found
13: /usr/microsoft.asc: KJt3bp3Ngn1vEYXwijGTa+FXz6GLHueJwF0I7ug34DgUkAFvAs8Hacr2DRYxL5RJ: not found
14: /usr/microsoft.asc: XdNgj4Jd2/g6T9InmWT0hASljur+dJnzNiNCkbn9KbX7J/qK1IbR8y560yRmFsU+: not found
15: /usr/microsoft.asc: NdCFTW7wY0Fb1fWJ+/KTsC4=: not found
16: /usr/microsoft.asc: =J6gs: not found
17: /usr/microsoft.asc: -----END: not found

我不确定存储文件是否只是个坏主意,但我真的没有其他方法绕过防火墙

如果您的文件系统上有该文件,则无需使用管道将其导入 apt-key add -。你可以简单地将文件名放在 apt-key add 命令上,像这样

COPY myfolder/microsoft.asc /usr/
RUN apt-get update 
    && apt-get install -y curl apt-transport-https locales gnupg2 
    && apt-key add /usr/microsoft.asc