我有一个ASP.Net Core Web API 2.2项目,该项目通常在本地Docker桌面上运行。我正在尝试在Azure的AKS上运行它,但它不会在那里运行,我也不明白为什么。
以下是我用于将项目发布到app
目录中的PowerShell脚本,该目录随后将插入到容器中:
Remove-Item ..\..\..\..\projects\MyProject.Selenium.Commom\src\Selenium.API\bin\Release\* -Force -Recurse
dotnet publish ..\..\..\..\projects\MyProject.Selenium.Commom\src\Selenium.Comum.sln -c Release -r linux-musl-x64
$path = (Get-Location).ToString() + "\app"
if (Test-Path($path))
{
Remove-Item -Path $path -Force -Recurse
}
New-Item -ItemType Directory -Force app
Get-ChildItem ..\..\..\..\projects\MyProject.Selenium.Commom\src\Selenium.API\bin\Release\netcoreapp2.2\linux-musl-x64\publish\* | Copy-Item -Destination .\app -Recurse
这是我的Dockerfile
# Build runtime image
FROM mcr.microsoft.com/dotnet/core/runtime:2.2-alpine3.9
WORKDIR /app /app
WORKDIR /app
ENTRYPOINT ["dotnet", "Selenium.API.dll"]
下面是我的Docker构建命令:
docker build -t mylocaldocker/selenium-web-app:latest -t mylocaldocker/selenium-web-app:v0.0.2 .
还有我的Docker运行命令
docker run --name selweb --detach --rm -p 85:80 mylocaldocker/selenium-web-app:latest
一切都变得顺畅流畅,而且我能够在端口85上本地发送请求而不会出现问题(IIS正在使用端口80)
但是,在Azure的AKS上执行类似的步骤,该容器将无法启动。我使用相同的PowerShell脚本发布应用程序,并且dockerfile也相同。我的构建命令发生了更改,以便可以推送到Azure的Docker注册表:
docker build -t myproject.azurecr.io/selenium-web-app:latest -t myproject.azurecr.io/selenium-web-app:v0.0.1 .
我登录到Azure Docker注册表,然后将映像推送到它:
docker push myproject.azurecr.io/selenium-web-app:latest
我已经创建了我的AKS集群,并获得了从注册表中提取图像的权限。我尝试使用以下命令在AKS上运行图像:
kubectl run seleniumweb --image myproject.azurecr.io/selenium-web-app:latest --port 80
我得到答复
deployment.apps "seleniumweb" created
但是,当我得到正在运行的吊舱时:
kubectl get pods
我的广告连播状态错误
NAME READY STATUS RESTARTS AGE
seleniumweb-7b5f645698-9g7f6 0/1 Error 4 1m
当我从吊舱中获取日志时:
kubectl logs seleniumweb-7b5f645698-9g7f6
我回来了:
Did you mean to run dotnet SDK commands? Please install dotnet SDK from:
https://go.microsoft.com/fwlink/?LinkID=798306&clcid=0x409
以下是kubectl描述广告连播的结果:
kubectl describe pods
Name: seleniumweb-7b5f645698-9g7f6
Namespace: default
Priority: 0
PriorityClassName: <none>
Node: aks-agentpool-41564776-0/10.240.0.4
Start Time: Sun, 02 Jun 2019 11:40:47 -0300
Labels: pod-template-hash=7b5f645698
run=seleniumweb
Annotations: <none>
Status: Running
IP: 10.240.0.25
Controlled By: ReplicaSet/seleniumweb-7b5f645698
Containers:
seleniumweb:
Container ID: docker://1d548f4934632efb0b7c5a59dd0ac2bd173f2ee8fa5196b45d480fb10e88a536
Image: myproject.azurecr.io/selenium-web-app:latest
Image ID: docker-pullable://myproject.azurecr.io/selenium-web-app@sha256:97e2915a8b43aa8e726799b76274bb9b5b852cb6c78a8630005997e310cfd41a
Port: 80/TCP
Host Port: 0/TCP
State: Waiting
Reason: CrashLoopBackOff
Last State: Terminated
Reason: Error
Exit Code: 145
Started: Sun, 02 Jun 2019 11:43:39 -0300
Finished: Sun, 02 Jun 2019 11:43:39 -0300
Ready: False
Restart Count: 5
Environment:
KUBERNETES_PORT_443_TCP_ADDR: myprojectus-dns-54302b78.hcp.eastus2.azmk8s.io
KUBERNETES_PORT: tcp://myprojectus-dns-54302b78.hcp.eastus2.azmk8s.io:443
KUBERNETES_PORT_443_TCP: tcp://myprojectus-dns-54302b78.hcp.eastus2.azmk8s.io:443
KUBERNETES_SERVICE_HOST: myprojectus-dns-54302b78.hcp.eastus2.azmk8s.io
Mounts:
/var/run/secrets/kubernetes.io/serviceaccount from default-token-mhvfv (ro)
Conditions:
Type Status
Initialized True
Ready False
ContainersReady False
PodScheduled True
Volumes:
default-token-mhvfv:
Type: Secret (a volume populated by a Secret)
SecretName: default-token-mhvfv
Optional: false
QoS Class: BestEffort
Node-Selectors: <none>
Tolerations: node.kubernetes.io/not-ready:NoExecute for 300s
node.kubernetes.io/unreachable:NoExecute for 300s
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Scheduled 5m default-scheduler Successfully assigned default/seleniumweb-7b5f645698-9g7f6 to aks-agentpool-41564776-0
Normal Created 4m (x4 over 5m) kubelet, aks-agentpool-41564776-0 Created container
Normal Started 4m (x4 over 5m) kubelet, aks-agentpool-41564776-0 Started container
Normal Pulling 3m (x5 over 5m) kubelet, aks-agentpool-41564776-0 pulling image "myproject.azurecr.io/selenium-web-app:latest"
Normal Pulled 3m (x5 over 5m) kubelet, aks-agentpool-41564776-0 Successfully pulled image "myproject.azurecr.io/selenium-web-app:latest"
Warning BackOff 20s (x24 over 5m) kubelet, aks-agentpool-41564776-0 Back-off restarting failed container
我不明白为什么,因为在本地Docker上一切正常。任何帮助将不胜感激。谢谢
答案 0 :(得分:1)
那个Dockerfile看起来很有趣。它什么也没做。 WORKDIR只是“为Dockerfile中跟随它的所有RUN,CMD,ENTRYPOINT,COPY和ADD指令设置工作目录”(来自docs.docker.com)。因此,您要设置工作目录两次,然后再进行其他设置。然后,入口点将指向不存在的.dll,因为您从未将其复制过。我想您想删除第一个WORKDIR命令,并在其余WORKDIR命令之后添加它:
COPY . ./
更好的是,使用two stage build,使其在docker上构建,然后将构建复制到发布的运行时映像。
我不知道为什么docker run在本地为您工作。是否以某种方式拾取了旧图像?基于您的Dockerfile,它不应运行。