gpt4 book ai didi

docker - 如何修复 Kubernetes 创建容器错误

转载 作者:行者123 更新时间:2023-12-02 11:39:18 29 4
gpt4 key购买 nike

当我尝试从 docker 镜像创建 pod 时,出现创建容器错误。这是我的 pod.yml 文件

apiVersion: v1
kind: Pod
metadata:
name: client
spec:
containers:
- image: es-tutorial_web
imagePullPolicy: Never
name: es-web
ports:
- containerPort: 3000
- image: es-tutorial_filebeat
imagePullPolicy: Never
name: es-filebeat

docker-compose.yml

version: '3.7'
services:
web:
build:
context: .
dockerfile: ./Dockerfile
container_name: test-app
working_dir: /usr/src/app
command: /bin/bash startup.sh
volumes:
- .:/usr/src/app
ports:
- "3000:3000"
networks:
- logs
filebeat:
build:
context: .
dockerfile: filebeat/Dockerfile
container_name: test-filebeat
volumes:
- .:/usr/src/app
depends_on:
- web
networks:
- logs

networks:
logs:
driver: bridge

kubectl 获取 pod

client                               1/2     CreateContainerError   0          24m

kubectl 描述客户端

Name:         client
Namespace: default
Priority: 0
Node: minikube/10.0.2.15
Start Time: Tue, 15 Oct 2019 15:29:02 +0700
Labels: <none>
Annotations: kubectl.kubernetes.io/last-applied-configuration:
{"apiVersion":"v1","kind":"Pod","metadata":{"annotations":{},"name":"client","namespace":"default"},"spec":{"containers":[{"image":"es-tut...
Status: Pending
IP: 172.17.0.8
Containers:
es-web:
Container ID:
Image: es-tutorial_web
Image ID:
Port: 3000/TCP
Host Port: 0/TCP
State: Waiting
Reason: CreateContainerError
Ready: False
Restart Count: 0
Environment: <none>
Mounts:
/var/run/secrets/kubernetes.io/serviceaccount from default-token-5ftqt (ro)
es-filebeat:
Container ID: docker://4174e7eb5bf8abe7662698c96d7945a546503f3c5494cad2ae10d2a8d4f02762
Image: es-tutorial_filebeat
Image ID: docker://sha256:4e3d24ef67bb05b2306eb49eab9d8a3520aa499e7a30cf0856b8658807b49b57
Port: <none>
Host Port: <none>
State: Running
Started: Tue, 15 Oct 2019 15:29:03 +0700
Ready: True
Restart Count: 0
Environment: <none>
Mounts:
/var/run/secrets/kubernetes.io/serviceaccount from default-token-5ftqt (ro)
Conditions:
Type Status
Initialized True
Ready False
ContainersReady False
PodScheduled True
Volumes:
default-token-5ftqt:
Type: Secret (a volume populated by a Secret)
SecretName: default-token-5ftqt
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 13m default-scheduler Successfully assigned default/client to minikube
Normal Pulled 13m kubelet, minikube Container image "es-tutorial_filebeat" already present on machine
Normal Created 13m kubelet, minikube Created container es-filebeat
Normal Started 13m kubelet, minikube Started container es-filebeat
Warning Failed 11m (x11 over 13m) kubelet, minikube Error: Error response from daemon: No command specified
Normal Pulled 3m26s (x50 over 13m) kubelet, minikube Container image "es-tutorial_web" already present on machine

docker 文件

...
RUN apt-get update && apt-get install -y curl

RUN curl -sL "https://deb.nodesource.com/setup_12.x" | bash - && apt-get install -y nodejs && echo 'node' > node
RUN mkdir -p /usr/src/app
COPY . /usr/src/app
WORKDIR /usr/src/app
RUN chmod +x startup.sh
RUN npm install -g nodemon

启动.sh

if [ ! -d /usr/src/app/node_modules ]; then
echo "Install dependencies..."
cd /usr/src/app && npm install --no-bin-links
fi
cd /usr/src/app && nodemon -L bin/www

我哪里错了?请帮助我

最佳答案

我相信你错过了CMDENTRYPOINT在您的 Dockerfile 中。他们需要运行容器。

它应该设置为您计划在执行容器时运行的一些默认命令。

如果 startup.sh 是您运行应用程序的脚本,请尝试以下操作:

ENTRYPOINT /usr/src/app/startup.sh

或者将您的 Dockerfile 修改为:

# ...
WORKDIR /usr/src/app
RUN chmod +x startup.sh
RUN npm install -g nodemon
RUN test ! -d /usr/src/app/node_modules && npm install --no-bin-links
ENTRYPOINT ["/usr/src/app/nodemon", "-L", "bin/www"]

关于docker - 如何修复 Kubernetes 创建容器错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58390812/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com