<p>To debug this, check the container logs and the container events.</p>

<ul>
<li>kubectl get pods</li>
<li>Find your pod name.</li>
<li>kubectl logs </li>
<li>If logs don't make it obvious...</li>
<li>kubectl get events</li>
</ul>

<p>If you deployed into a namespace, make sure to add -n  to all commands.</p>

<p>This should reveal basically everything. If you're stuck, you can also browse around the k8s dashboard if you haven't yet.  But that probably wouldn't reveal much more than the CLI is with these commands.</p>

CC BY-SA 4.0
2020-02-05T01:20:44.967Z
2020-02-05T01:20:44.967Z
John Humphreys
<p>K8s works with concept of Health Check, in your application you have some port or command/trigger that K8s can monitoring?
Maybe because of that your container is not works.</p>

CC BY-SA 4.0
2020-02-04T21:50:26.953Z
2020-02-04T21:50:26.953Z
Vader
<ol>
<li>It looks like your dockerfile has both <code>CMD</code> and <code>ENTRYPOINT</code>, so it’s highly likely that what gets invoked as a commsnd is <code>pwsh -f /app/Start-Test.ps1 /app/Start-Test.ps1</code>. It could be that this command gives an error, <code>kubectl describe &lt;your-pod&gt;</code> might shed some light onto what’s going on. Check <a href="https://stackoverflow.com/a/34245657">this answer</a> for details on difference between <code>CMD</code> and <code>ENTRYPOINT</code></li>
<li>If you’re getting <code>ImagePullBackOff</code>, then image might be missing from the registry or secrets are invalid. </li>
</ol>

<p>Hope this helps</p>

CC BY-SA 4.0
2020-02-10T19:06:02.807Z
2020-02-10T19:06:02.807Z
Alexey Skolyarov
<p>When running PowerShell as the <code>ENTRYPOINT</code> for the container PowerShell should be executed as:</p>

<pre><code>ENTRYPOINT ["pwsh", "-NoExit", "-File", "/app/Start-Test.ps1"]
</code></pre>

<p>The short form of each of those parameters can be used. Additionally, the <code>-NoExit</code> flag will help with debugging the issue in for your deployment. The reason the <code>-NoExit</code> flag helps is the deployment stays alive long enough for you to confirm the logs and the container health.</p>

<p>This answer along with answers from Alexey Skolyarov and John Humphreys to debug and solve my issue.</p>

CC BY-SA 4.0
2020-02-11T20:36:11.487Z
2020-02-11T20:36:11.487Z
Dodzi Dzakuma
<p><strong>Background</strong></p>

<p>I have a container that I have defined with an <code>CMD</code> and an <code>ENTRYPOINT</code> in Docker. When I run the following command my container runs with no issues whatsoever.</p>

<pre><code>docker run --rm -ti custom-container:latest
</code></pre>

<p>Here is the definition for my container:</p>

<pre><code>FROM mcr.microsoft.com/powershell:6.2.3-ubuntu-bionic
COPY . /app
WORKDIR /app

CMD ["/app/Start-Test.ps1"]
ENTRYPOINT ["pwsh", "-f", "/app/Start-Test.ps1"]
</code></pre>

<p>The script <code>Start-Test.ps1</code> is just an infinite loop that writes <code>Hello World!</code> to host.</p>

<p><strong>Problem</strong></p>

<p>When I go to run my container in Kubernetes, my container refuses to run. </p>

<p>Kubernetes is able to pull my image and it attempts to spin up the container, but I keep getting a status of BackedOff from Kubernetes.</p>

<p>I've gone through and tried to figure out why this is happening because the container runs perfectly fine in Docker.</p>

<p>I only have issues when I try to run the container in Kubernetes.</p>

<p>Here is the definition for my Kubernetes deployment.</p>

<pre><code>apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: my-custom-container
spec:
  replicas: 1
  selector:
    matchLabels:
      app: my-custom-container
  template:
    metadata:
      labels:
        app: my-custom-container
    spec:
      containers:
      - name: my-custom-container
        image: repository-url.io/custom-container:latest
      imagePullSecrets:
      - name: regcred
</code></pre>

<p><strong>Question</strong></p>

<p>What is the issue preventing my container from running when it runs with no problems in Docker?</p>

<p>Additionally, yes I would like to use PowerShell as my entry point. It should be possible to use any scripting langauge (bash, Ruby, Python, Perl, etc) as an entry point.</p>

CC BY-SA 4.0
2020-02-04T03:29:00.347Z
What is the contents of your K8S logs? `kubectl logs <pod name>`. Please add the log data to your question.
Steven K7FAQ
<docker><kubernetes><containers><powershell><azure-kubernetes-service>
Why will my container run in Docker, but will not run in Kubernetes?
Dodzi Dzakuma
# Why will my container run in Docker, but will not run in Kubernetes?

(Asked by: username_0 on 2020-02-03)

Background
I have a container that I have defined with an CMD and an ENTRYPOINT in Docker. When I run the following command my container runs with no issues whatsoever.
docker run --rm -ti custom-container:latest

Here is the definition for my container:
FROM mcr.microsoft.com/powershell:6.2.3-ubuntu-bionic
COPY . /app
WORKDIR /app

CMD ["/app/Start-Test.ps1"]
ENTRYPOINT ["pwsh", "-f", "/app/Start-Test.ps1"]

The script Start-Test.ps1 is just an infinite loop that writes Hello World! to host.
Problem
When I go to run my container in Kubernetes, my container refuses to run. 
Kubernetes is able to pull my image and it attempts to spin up the container, but I keep getting a status of BackedOff from Kubernetes.
I've gone through and tried to figure out why this is happening because the container runs perfectly fine in Docker.
I only have issues when I try to run the container in Kubernetes.
Here is the definition for my Kubernetes deployment.
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: my-custom-container
spec:
  replicas: 1
  selector:
    matchLabels:
      app: my-custom-container
  template:
    metadata:
      labels:
        app: my-custom-container
    spec:
      containers:
      - name: my-custom-container
        image: repository-url.io/custom-container:latest
      imagePullSecrets:
      - name: regcred

Question
What is the issue preventing my container from running when it runs with no problems in Docker?
Additionally, yes I would like to use PowerShell as my entry point. It should be possible to use any scripting langauge (bash, Ruby, Python, Perl, etc) as an entry point.

**Tags:** docker, kubernetes, containers, powershell, azure-kubernetes-service

> **Comments:**
> **username_1**: What is the contents of your K8S logs? `kubectl logs <pod name>`. Please add the log data to your question.  

---

## 4 answers

### Answer by username_2 on 2020-02-05. Score: 2

To debug this, check the container logs and the container events.

* kubectl get pods
* Find your pod name.
* kubectl logs
* If logs don't make it obvious...
* kubectl get events

If you deployed into a namespace, make sure to add -n to all commands.

This should reveal basically everything. If you're stuck, you can also browse around the k8s dashboard if you haven't yet. But that probably wouldn't reveal much more than the CLI is with these commands.


---

### Answer by username_3 on 2020-02-04. Score: 1

K8s works with concept of Health Check, in your application you have some port or command/trigger that K8s can monitoring?
Maybe because of that your container is not works.


---

### Answer by username_4 on 2020-02-10. Score: 1

1. It looks like your dockerfile has both `CMD` and `ENTRYPOINT`, so it’s highly likely that what gets invoked as a commsnd is `pwsh -f /app/Start-Test.ps1 /app/Start-Test.ps1`. It could be that this command gives an error, `kubectl describe`  might shed some light onto what’s going on. Check [this answer](https://stackoverflow.com/a/34245657) for details on difference between `CMD` and `ENTRYPOINT`
2. If you’re getting `ImagePullBackOff`, then image might be missing from the registry or secrets are invalid.

Hope this helps


---

### Answer by username_0 on 2020-02-11. Score: 0

When running PowerShell as the ENTRYPOINT for the container PowerShell should be executed as:
ENTRYPOINT ["pwsh", "-NoExit", "-File", "/app/Start-Test.ps1"]

The short form of each of those parameters can be used. Additionally, the -NoExit flag will help with debugging the issue in for your deployment. The reason the -NoExit flag helps is the deployment stays alive long enough for you to confirm the logs and the container health.
This answer along with answers from username_4 and username_2 to debug and solve my issue.


---

