当我通过k8s创建pod时,出现create container错误,这是我的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 get pods
client 1/2 CreateContainerError 0 24m
kubectl describe client
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
Dockerfile
...
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
startup.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
Where is my wrong? Please help me
Dockerfile中缺少
CMD
或ENTRYPOINT
。如果
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"]
谢谢,加上就可以了
你的答案