执行Curl呼叫后,AZ CLI在Mac上的Docker Image上丢失

发布于 2025-01-22 02:29:03 字数 5182 浏览 3 评论 0原文

我在dockerfile中有以下内容:

FROM mcr.microsoft.com/dotnet/sdk:6.0
RUN apt update
RUN apt-get install vim -y
COPY . /builds
RUN curl -sL https://aka.ms/InstallAzureCLIDeb | bash
RUN apt-get install curl && curl -sL https://deb.nodesource.com/setup_12.x | bash -
RUN apt-get install nodejs
RUN npm install -g azure-functions-core-tools@4 --unsafe-perm true

此时,如果我使用此新图像创建一个容器,在我的Windows主机上,我可以做到这一点:

root@5a75ab66011b:/builds# az --version
azure-cli                         2.35.0

core                              2.35.0
telemetry                          1.0.6

Dependencies:
msal                              1.17.0
azure-mgmt-resource               20.0.0

Python location '/opt/az/bin/python3'
Extensions directory '/root/.azure/cliextensions'

Python (Linux) 3.8.12 (default, Apr  1 2022, 06:20:19)
[GCC 10.2.1 20210110]

Legal docs and information: aka.ms/AzureCliLegal


Your CLI is up-to-date.

Please let us know how we are doing: https://aka.ms/azureclihats
and let us know if you're interested in trying out our newest features: https://aka.ms/CLIUXstudy
root@5a75ab66011b:/builds#

在我的M1 MacBook Pro上:

root@4fb97a21813a:/builds# az
qemu-x86_64: Could not open '/lib64/ld-linux-x86-64.so.2': No such file or directory
root@4fb97a21813a:/builds# 

因此,我尝试手动重做Curl命令,如下

root@4fb97a21813a:/builds# curl -sL https://aka.ms/InstallAzureCLIDeb | bash
Hit:1 http://deb.debian.org/debian bullseye InRelease
Hit:2 http://deb.debian.org/debian bullseye-updates InRelease                                                                                            
Hit:3 http://security.debian.org/debian-security bullseye-security InRelease                                                                             
Hit:4 https://packages.microsoft.com/repos/azure-cli bullseye InRelease                                                                                  
Hit:5 https://deb.nodesource.com/node_12.x bullseye InRelease             
Reading package lists... Done                       
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
apt-transport-https is already the newest version (2.2.4).
curl is already the newest version (7.74.0-1.3+deb11u1).
gnupg is already the newest version (2.2.27-2+deb11u1).
lsb-release is already the newest version (11.1.0).
0 upgraded, 0 newly installed, 0 to remove and 2 not upgraded.
Hit:1 http://deb.debian.org/debian bullseye InRelease
Hit:2 http://deb.debian.org/debian bullseye-updates InRelease                                                                      
Hit:3 http://security.debian.org/debian-security bullseye-security InRelease                                                       
Hit:4 https://packages.microsoft.com/repos/azure-cli bullseye InRelease                                                            
Hit:5 https://deb.nodesource.com/node_12.x bullseye InRelease             
Reading package lists... Done                       
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
azure-cli is already the newest version (2.35.0-1~bullseye).
0 upgraded, 0 newly installed, 0 to remove and 2 not upgraded.

root@4fb97a21813a:/builds# az
qemu-x86_64: Could not open '/lib64/ld-linux-x86-64.so.2': No such file or directory
root@4fb97a21813a:/builds#   

:指示我已经安装了Azure-CLI ...但是它不会运行。 任何技巧都将不胜感激。

编辑1

我尝试过这样的图像:

docker build -t azuredeployment . --platform linux/amd64     

而不是:

docker build -t azuredeployment .

但没有骰子。我得到相同的结果。

我还试图改变运行Docker容器的方式,但我似乎无法使命令运行:

 docker run -d azuredeployment --platform linux/x86_64

给我错误

docker: Error response from daemon: OCI runtime create failed: container_linux.go:380: starting container process caused: exec: "--platform": executable file not found in $PATH: unknown.

编辑2

使它大部分工作。

我更改了Docker文件:

 FROM mcr.microsoft.com/dotnet/sdk:6.0 \

对此:

 FROM --platform=linux/amd64 mcr.microsoft.com/dotnet/sdk:6.0 

它有效。尽管我在Docker桌面上旁边有一个带有感叹号的小图标,说该图像可能无法正常运行。

我还尝试使用这样的ARM64版本:

 FROM --platform=linux/arm64 mcr.microsoft.com/dotnet/sdk:6.0 

我在运行容器旁边没有警告图标,但是...我仍然收到相同的错误消息。

编辑3

因此,这是我在from中使用的语法:

FROM mcr.microsoft.com/dotnet/sdk:6.0.202-bullseye-slim-amd64
RUN apt update && apt-get install vim -y
COPY . /builds
RUN curl -sL https://aka.ms/InstallAzureCLIDeb | bash
RUN apt-get install curl && curl -sL https://deb.nodesource.com/setup_12.x | bash -
RUN apt-get install nodejs
RUN npm install -g azure-functions-core-tools@4 --unsafe-perm true

AZ CLI似乎安装正确。但这是显示运行容器状态的屏幕截图。您还可以看到我要描述的警告图标。

I have the following in my Dockerfile:

FROM mcr.microsoft.com/dotnet/sdk:6.0
RUN apt update
RUN apt-get install vim -y
COPY . /builds
RUN curl -sL https://aka.ms/InstallAzureCLIDeb | bash
RUN apt-get install curl && curl -sL https://deb.nodesource.com/setup_12.x | bash -
RUN apt-get install nodejs
RUN npm install -g azure-functions-core-tools@4 --unsafe-perm true

At this point if I create a container using this new image, on my windows host I can do this:

root@5a75ab66011b:/builds# az --version
azure-cli                         2.35.0

core                              2.35.0
telemetry                          1.0.6

Dependencies:
msal                              1.17.0
azure-mgmt-resource               20.0.0

Python location '/opt/az/bin/python3'
Extensions directory '/root/.azure/cliextensions'

Python (Linux) 3.8.12 (default, Apr  1 2022, 06:20:19)
[GCC 10.2.1 20210110]

Legal docs and information: aka.ms/AzureCliLegal


Your CLI is up-to-date.

Please let us know how we are doing: https://aka.ms/azureclihats
and let us know if you're interested in trying out our newest features: https://aka.ms/CLIUXstudy
root@5a75ab66011b:/builds#

On my m1 macbook pro:

root@4fb97a21813a:/builds# az
qemu-x86_64: Could not open '/lib64/ld-linux-x86-64.so.2': No such file or directory
root@4fb97a21813a:/builds# 

So I tried to manually redo the curl command like this:

root@4fb97a21813a:/builds# curl -sL https://aka.ms/InstallAzureCLIDeb | bash
Hit:1 http://deb.debian.org/debian bullseye InRelease
Hit:2 http://deb.debian.org/debian bullseye-updates InRelease                                                                                            
Hit:3 http://security.debian.org/debian-security bullseye-security InRelease                                                                             
Hit:4 https://packages.microsoft.com/repos/azure-cli bullseye InRelease                                                                                  
Hit:5 https://deb.nodesource.com/node_12.x bullseye InRelease             
Reading package lists... Done                       
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
apt-transport-https is already the newest version (2.2.4).
curl is already the newest version (7.74.0-1.3+deb11u1).
gnupg is already the newest version (2.2.27-2+deb11u1).
lsb-release is already the newest version (11.1.0).
0 upgraded, 0 newly installed, 0 to remove and 2 not upgraded.
Hit:1 http://deb.debian.org/debian bullseye InRelease
Hit:2 http://deb.debian.org/debian bullseye-updates InRelease                                                                      
Hit:3 http://security.debian.org/debian-security bullseye-security InRelease                                                       
Hit:4 https://packages.microsoft.com/repos/azure-cli bullseye InRelease                                                            
Hit:5 https://deb.nodesource.com/node_12.x bullseye InRelease             
Reading package lists... Done                       
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
azure-cli is already the newest version (2.35.0-1~bullseye).
0 upgraded, 0 newly installed, 0 to remove and 2 not upgraded.

root@4fb97a21813a:/builds# az
qemu-x86_64: Could not open '/lib64/ld-linux-x86-64.so.2': No such file or directory
root@4fb97a21813a:/builds#   

It seems to be indicating that I have installed azure-cli ... but it won't run.
Any tips would be appreciated.

Edit 1

I've tried building the image like this:

docker build -t azuredeployment . --platform linux/amd64     

instead of:

docker build -t azuredeployment .

but no dice. I get the same results.

I also tried to change the way I run the docker container but I can't seem to get the command going :

 docker run -d azuredeployment --platform linux/x86_64

gives me the error

docker: Error response from daemon: OCI runtime create failed: container_linux.go:380: starting container process caused: exec: "--platform": executable file not found in $PATH: unknown.

EDIT 2

Got it mostly working.
I changed the docker file from this:

 FROM mcr.microsoft.com/dotnet/sdk:6.0 \

to this:

 FROM --platform=linux/amd64 mcr.microsoft.com/dotnet/sdk:6.0 

and it works. Albeit, I have this little icon with an exclamation mark next to it in docker desktop saying the image may not run properly.

I also tried to use the arm64 version like this:

 FROM --platform=linux/arm64 mcr.microsoft.com/dotnet/sdk:6.0 

I don't have the warning icon next to my running container but ... i still get the same error message.

EDIT 3

So in this end, this is the syntax I'm working with in the FROM :

FROM mcr.microsoft.com/dotnet/sdk:6.0.202-bullseye-slim-amd64
RUN apt update && apt-get install vim -y
COPY . /builds
RUN curl -sL https://aka.ms/InstallAzureCLIDeb | bash
RUN apt-get install curl && curl -sL https://deb.nodesource.com/setup_12.x | bash -
RUN apt-get install nodejs
RUN npm install -g azure-functions-core-tools@4 --unsafe-perm true

It seems the az cli installs properly. But here's a screenshot showing the status of the running container. You can also see the warning icon I was trying to describe.

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文