mockserver icon indicating copy to clipboard operation
mockserver copied to clipboard

Add curl or some other tool to be able to implement docker-compose healthcheck

Open akefirad opened this issue 2 years ago • 2 comments

Describe the feature request Add curl or some other tool to the docker image to be able to make simple HTTP call (mainly to do health checks)

What you are trying to do I'm not sure what's the best way to do this, but normally I add a healthcheck to services in my test dependencies docker-compose file. This is not possible for mockserver since the docker image is distroless (and doesn't have curl).

The solution you'd like Can we have a tool to be able to do simple HTTP call in the docker container?

Describe alternatives you've considered I'm not sure, but maybe there's other way to do this?

Thanks.

akefirad avatar Jun 02 '23 07:06 akefirad

I also could not get this to work +1 for this, this thing is a MockServer, why do we aim for such a tiny image?

lvijnck avatar Jul 20 '23 15:07 lvijnck

There is a workaround for that with a multi-stage Docker build in order to keep it light as well, since I had exactly the same issue. You could add a busybox image as one of your base images and then add curl on top. For example:

FROM busybox:1.35.0-uclibc@sha256:<yourSHA> as busybox

FROM mockserver/mockserver:5.15.0@sha256:<yourSHA>

COPY --from=busybox /bin /bin

USER root

RUN wget -O curl.tar.xz https://github.com/stunnel/static-curl/releases/download/8.2.1/curl-static-amd64-8.2.1.tar.xz &&  \
    tar -xf curl.tar.xz --directory /usr/bin

CMD [ "bin/sh" ]

Then you use the above in your docker-compose in the following manner:

  mockserver:
    image: <your-new-mockserver-image>
    deploy:
      replicas: 2
      resources:
        limits:
          memory: 2g
    ports:
      - "1081-1082:1080"
    environment:
      MOCKSERVER_PROPERTY_FILE: /config/mockserver.properties
    volumes:
      - ./mock/initializerJson.json:/config/initializerJson.json
      - ./mock/mockserver.properties:/config/mockserver.properties
    healthcheck:
      test: ["CMD-SHELL", "curl -sSf -X PUT http://localhost:1080/mockserver/status || exit 1"]
      interval: 5s
      timeout: 15s
      retries: 30
    networks: *mockserver-network

Please ignore the replicas: 2 since the above is using nginx as an LB for mockserver.

However, I really hope that you have already found a solution until now :)

sgkiokas avatar Sep 08 '23 11:09 sgkiokas