2

I am working with Docker and I have created a Dockerfile which converts my dotnet application into an image. I can then run this image and everything is working fine. I am using mcr.microsoft.com/dotnet/core/sdk:3.1-nanoserver-1809 AS base.

Now, I wanted to add the 'HealthCheck' feature of Docker. In that HealthCheck, I want to use some Powershell logic, but from the moment I use Powershell, de HealthCheck gets classified as unhealthy.

For example:

HEALTHCHECK CMD powershell -command exit 0

Results in an unhealthy container.

For example:

HEALTHCHECK CMD exit 0

Results in a healthy container

Any powershell logic I try to insert, which either returns or exits a 0, give me unhealthy containers. Right now, I'm thinking that it is the powershell just erroring whatever the logic is.

Anyone can hint at what I am doing wrong to get some powershell code login inside my Docker Healthcheck? I need this powershell code within the HealthCheck for a specific reason which is not really important.

Thanks


EDIT: I have also tried:

HEALTHCHECK CMD powershell -command return 0

and

HEALTHCHECK CMD powershell -command Write-Host 0

Both with the same result: an unhealthy container.

6
  • Can you check what the exit code is when you run that powershell command normally? Commented Aug 4, 2020 at 16:17
  • If I run 'exit 0' in my powershell window, it just closes my powershell window. According to the docs of Docker Healthcheck tell me: "The command’s exit status indicates the health status of the container. The possible values are: 0: success - the container is healthy and ready for use 1: unhealthy - the container is not working correctly 2: reserved - do not use this exit code " So that is why I'm trying it like this. Commented Aug 4, 2020 at 16:43
  • Could you create a script with that command in it, run it, and check the exit code? Sorry, I'm not familiar with PowerShell; I mostly write Bash. Commented Aug 4, 2020 at 16:58
  • I can surely do that, not so familiar myself. But what exactly do you mean with 'check the exit code'? Just run the dedicated script and see what it does? Commented Aug 4, 2020 at 17:16
  • 1
    When running the ps1 file with 'exit 0' inside, and then retrieve the $LastExitCode, I get printed a 0. When running the ps1 file with 'exit 1' inside, and then retrieve the $LastExitCode, I get printed a 1. So I see no reason why this should not work in Docker Healthcheck.. Commented Aug 4, 2020 at 17:40

1 Answer 1

1

We use the following command in AWS ECS

powershell -c 'try { if ((iwr -Uri http://localhost:${CONTAINER_PORT}${HEALTHCHECK_PATH} -UseBasicParsing -DisableKeepAlive).StatusCode -eq 200) {return 0} return 1; } catch { return 1 }'

We are running windows 2016 and 20H2 containers

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.