mock-server / mockserver

MockServer enables easy mocking of any system you integrate with via HTTP or HTTPS with clients written in Java, JavaScript and Ruby. MockServer also includes a proxy that introspects all proxied traffic including encrypted SSL traffic and supports Port Forwarding, Web Proxying (i.e. HTTP proxy), HTTPS Tunneling Proxying (using HTTP CONNECT) and SOCKS Proxying (i.e. dynamic port forwarding).
http://mock-server.com
Apache License 2.0
4.58k stars 1.07k forks source link

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

Open akefirad opened 1 year ago

akefirad commented 1 year ago

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.

lvijnck commented 1 year ago

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?

sgkiokas commented 1 year ago

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 :)