Azure / azure-cosmos-db-emulator-docker

This repo serves as hub for managing issues, gathering feedback, and having discussions regarding the Cosmos DB Emulator Docker.
https://learn.microsoft.com/en-us/azure/cosmos-db/how-to-develop-emulator?tabs=docker-linux%2Ccsharp&pivots=api-nosql
MIT License
149 stars 45 forks source link

Linux docker emulator lacks 'curl' command #103

Open jalbiero opened 1 month ago

jalbiero commented 1 month ago

Describe the bug The linux emulator doesn't provide the curl command (or similar like wget), so it is not possible to perform a basic healtcheck (as is usual with docker compose)

Disclaimer: IMHO this is a bug, not a feature request, because a common operation with docker compose cannot be performed (unless there is an alternative way to check when CosmosDB service is ready)

To Reproduce

  1. Suppose the following docker compose file (compose.yaml):
services:
  CosmosDb:
    image: mcr.microsoft.com/cosmosdb/linux/azure-cosmos-emulator
    ports:
      - 443:443
      - 8081:8081
      - 10250-10255:10250-10255
    healthcheck:
      test: ["CMD", "curl", "-f", "-k", "https://localhost:8081/_explorer/emulator.pem"]
      interval: 10s
      retries: 12
      timeout: 3s
  1. Run the service and wait:
PS C:\Users\FooUser\CosmosDbTest> docker compose up --wait
[+] Running 0/1
 - Container cosmosdbtest-CosmosDb-1  Waiting        60.9s 
container cosmosdbtest-CosmosDb-1 is unhealthy
  1. The container inspection reveals the problem, curl is missing:
PS C:\Users\FooUser\CosmosDbTest> docker inspect cosmosdbtest-CosmosDb-1
[
    {
        "Id": "65f4798648c3889e9e23608addf423e33d9f4a47ab2ae9512fec65658a0250e5",
        "Created": "2024-07-10T14:41:28.483636479Z",
        "Path": "/usr/local/bin/cosmos/start.sh",
        "Args": [],
        "State": {
            "Status": "running",
            "Running": true,
            "Paused": false,
            "Restarting": false,
            "OOMKilled": false,
            "Dead": false,
            "Pid": 48405,
            "ExitCode": 0,
            "Error": "",
            "StartedAt": "2024-07-10T14:41:39.46781182Z",
            "FinishedAt": "0001-01-01T00:00:00Z",
            "Health": {
                "Status": "unhealthy",
                "FailingStreak": 308,
                "Log": [
                    {
                        "Start": "2024-07-10T15:32:28.363369721Z",
                        "End": "2024-07-10T15:32:28.390398997Z",
                        "ExitCode": -1,
                        "Output": "OCI runtime exec failed: exec failed: unable to start container process: exec: \"curl\": executable file not found in $PATH: unknown"
                    },
                    {
                        "Start": "2024-07-10T15:32:38.391259729Z",
                        "End": "2024-07-10T15:32:38.41879366Z",
                        "ExitCode": -1,
                        "Output": "OCI runtime exec failed: exec failed: unable to start container process: exec: \"curl\": executable file not found in $PATH: unknown"
                    },
                    ...

Expected behavior If curl is provided the following is expected:

PS C:\Users\FooUser\CosmosDbTest> docker compose up --wait
[+] Running 1/1
 ✔ Container cosmosdbwrapper-CosmosDb-1  Healthy

Desktop

Docker Images Used

Docker Environment

jrichardsz commented 1 month ago

curl could help us to add custom health checks like Jalbiero or :

    healthcheck:
      test:  curl --insecure --fail https://localhost:8081/_explorer/index.html
jalbiero commented 1 month ago

I am using the following workaround, a "wrapper" image (cosmos-emulator-wrapper) that contains the curl utility:

services:
  CosmosDb:
    image: cosmos-emulator-wrapper
    build:
      dockerfile_inline: |
        FROM mcr.microsoft.com/cosmosdb/linux/azure-cosmos-emulator:latest
        RUN apt-get update && \
            DEBIAN_FRONTEND=noninteractive apt-get install -y \
            curl
    ports:
      - 443:443
      - 8081:8081
      - 10250-10255:10250-10255
    healthcheck:
      test: ["CMD", "curl", "-f", "-k", "https://localhost:8081/_explorer/emulator.pem"]
      interval: 10s
      retries: 12
      timeout: 3s