[GH-ISSUE #904] Health Checks for Docker Compose #140

Closed
opened 2026-03-03 12:08:40 +03:00 by kerem · 4 comments
Owner

Originally created by @lauslim12 on GitHub (Aug 25, 2022).
Original GitHub issue: https://github.com/fsouza/fake-gcs-server/issues/904

Hello!

I have a question: is it possible for this Fake GCS Server to have a dedicated endpoint for health checks? I am using docker compose to provision my infrastructures for development purposes like the following:

version: "3.9"

services:
  gcs:
    container_name: googlecloudstorage
    image: fsouza/fake-gcs-server
    command: -scheme http
    ports:
      - 4443:4443
    volumes:
      - ./testdata/gcs-data:/storage
    # I want to have a health check, but when I try to ping the server, it always returns 404, thus resulting in an unhealthy state... 
    # healthcheck:

  postgres:
    container_name: postgres
    image: postgres:14.3
    ports:
      - 5432:5432
    volumes:
      - ./testdata/postgres-data:/var/lib/postgresql
    environment:
      POSTGRES_USER: project
      POSTGRES_DB: project
      POSTGRES_HOST_AUTH_METHOD: trust
    healthcheck:
      test: ["CMD-SHELL", "pg_isready"]
      interval: 30s
      timeout: 20s
      retries: 3

volumes:
  gcs-data:
  postgres-data:

I'm trying to do health checks by pinging it like the following (via curl, my Fake GCS server is hosted in 192.168.1.6:4443):

$ curl -I 192.168.1.6:4443
HTTP/1.1 404 Not Found
Content-Type: text/plain; charset=utf-8
X-Content-Type-Options: nosniff
Date: Thu, 25 Aug 2022 14:51:00 GMT
Content-Length: 19

$ curl -I 192.168.1.6:4443/storage/v1/b/sample-bucket
HTTP/1.1 404 Not Found
Content-Type: text/plain; charset=utf-8
X-Content-Type-Options: nosniff
Date: Thu, 25 Aug 2022 14:51:08 GMT
Content-Length: 10

$ curl -I 192.168.1.6:4443/storage/v1/b/sample-bucket/o/
HTTP/1.1 404 Not Found
Content-Type: text/plain; charset=utf-8
X-Content-Type-Options: nosniff
Date: Thu, 25 Aug 2022 14:51:25 GMT
Content-Length: 10

When I try to query/ping the Fake GCS server, it always returns 404 Not Found. Is this intentional? Is there any endpoints which I can use for health checks only? Because if I try to use the 404 Not Found status as my health check, the Docker will always mark the container as unhealthy, which is of course something that we do not want, and it is false negative (it works properly even when the state is in an unhealthy state).

Thank you for your help and answer!

Originally created by @lauslim12 on GitHub (Aug 25, 2022). Original GitHub issue: https://github.com/fsouza/fake-gcs-server/issues/904 Hello! I have a question: is it possible for this Fake GCS Server to have a dedicated endpoint for health checks? I am using `docker compose` to provision my infrastructures for development purposes like the following: ```yml version: "3.9" services: gcs: container_name: googlecloudstorage image: fsouza/fake-gcs-server command: -scheme http ports: - 4443:4443 volumes: - ./testdata/gcs-data:/storage # I want to have a health check, but when I try to ping the server, it always returns 404, thus resulting in an unhealthy state... # healthcheck: postgres: container_name: postgres image: postgres:14.3 ports: - 5432:5432 volumes: - ./testdata/postgres-data:/var/lib/postgresql environment: POSTGRES_USER: project POSTGRES_DB: project POSTGRES_HOST_AUTH_METHOD: trust healthcheck: test: ["CMD-SHELL", "pg_isready"] interval: 30s timeout: 20s retries: 3 volumes: gcs-data: postgres-data: ``` I'm trying to do health checks by pinging it like the following (via `curl`, my Fake GCS server is hosted in `192.168.1.6:4443`): ```bash $ curl -I 192.168.1.6:4443 HTTP/1.1 404 Not Found Content-Type: text/plain; charset=utf-8 X-Content-Type-Options: nosniff Date: Thu, 25 Aug 2022 14:51:00 GMT Content-Length: 19 $ curl -I 192.168.1.6:4443/storage/v1/b/sample-bucket HTTP/1.1 404 Not Found Content-Type: text/plain; charset=utf-8 X-Content-Type-Options: nosniff Date: Thu, 25 Aug 2022 14:51:08 GMT Content-Length: 10 $ curl -I 192.168.1.6:4443/storage/v1/b/sample-bucket/o/ HTTP/1.1 404 Not Found Content-Type: text/plain; charset=utf-8 X-Content-Type-Options: nosniff Date: Thu, 25 Aug 2022 14:51:25 GMT Content-Length: 10 ``` When I try to query/ping the Fake GCS server, it always returns `404 Not Found`. Is this intentional? Is there any endpoints which I can use for health checks only? Because if I try to use the `404 Not Found` status as my health check, the Docker will always mark the container as unhealthy, which is of course something that we do not want, and it is false negative (it works properly even when the state is in an unhealthy state). Thank you for your help and answer!
kerem closed this issue 2026-03-03 12:08:40 +03:00
Author
Owner

@fsouza commented on GitHub (Aug 25, 2022):

/storage/v1/b should always work, as that list the buckets in the server (it'll just return an empty list if there are no buckets), but I could swear we had a dedicated healthcheck URL.

We can add one at /_internal/healthcheck or something like that, that's not a lot of work.

edit: using a custom healthcheck URL is better because it won't do any host validation.

<!-- gh-comment-id:1227377428 --> @fsouza commented on GitHub (Aug 25, 2022): `/storage/v1/b` should always work, as that list the buckets in the server (it'll just return an empty list if there are no buckets), but I could swear we had a dedicated healthcheck URL. We can add one at `/_internal/healthcheck` or something like that, that's not a lot of work. **edit:** using a custom healthcheck URL is better because it won't do any host validation.
Author
Owner

@lauslim12 commented on GitHub (Aug 26, 2022):

Sorry for the late response!

Apparently, /storage/v1/b does not work either for me... I even have a bucket there already, but the server responds with 404 Not Found.

Projects > curl -I 192.168.1.6:4443/storage/v1/b
HTTP/1.1 404 Not Found
Content-Type: text/plain; charset=utf-8
X-Content-Type-Options: nosniff
Date: Fri, 26 Aug 2022 10:22:58 GMT
Content-Length: 10

Projects > curl 192.168.1.6:4443/storage/v1/b
{"kind":"storage#buckets","items":[{"kind":"storage#bucket","id":"sample-bucket","name":"sample-bucket","versioning":{},"timeCreated":"0001-01-01T00:00:00Z","location":"US-CENTRAL1"}]}

If we create a health check endpoint at internal/healthcheck.go, do you have any idea on how to start working on that? I think I want to try to tackle this on (with your permission of course).

In my mind...

  • A user pings the Fake GCS server, let's say in / path, and it should return 200 OK and nothing else.

But what do you think?

<!-- gh-comment-id:1228325711 --> @lauslim12 commented on GitHub (Aug 26, 2022): Sorry for the late response! Apparently, `/storage/v1/b` does not work either for me... I even have a bucket there already, but the server responds with `404 Not Found`. ```bash Projects > curl -I 192.168.1.6:4443/storage/v1/b HTTP/1.1 404 Not Found Content-Type: text/plain; charset=utf-8 X-Content-Type-Options: nosniff Date: Fri, 26 Aug 2022 10:22:58 GMT Content-Length: 10 Projects > curl 192.168.1.6:4443/storage/v1/b {"kind":"storage#buckets","items":[{"kind":"storage#bucket","id":"sample-bucket","name":"sample-bucket","versioning":{},"timeCreated":"0001-01-01T00:00:00Z","location":"US-CENTRAL1"}]} ``` If we create a health check endpoint at `internal/healthcheck.go`, do you have any idea on how to start working on that? I think I want to try to tackle this on (with your permission of course). In my mind... - A user pings the Fake GCS server, let's say in `/` path, and it should return `200 OK` and nothing else. But what do you think?
Author
Owner

@fsouza commented on GitHub (Aug 26, 2022):

@lauslim12 can you try #906?

<!-- gh-comment-id:1229016296 --> @fsouza commented on GitHub (Aug 26, 2022): @lauslim12 can you try #906?
Author
Owner

@lauslim12 commented on GitHub (Aug 27, 2022):

Yep, that works properly. Thank you for adding the endpoint! Here, I will cross-post the configuration I use to perform the health check:

I performed the health check on my machine by doing:

akasha @ Akashas-MacBook-Pro: ~/Projects/fake-gcs-server                                                                                                                                 
$ curl -I -X GET localhost:4443/_internal/healthcheck
HTTP/1.1 200 OK
Date: Sat, 27 Aug 2022 03:17:04 GMT
Content-Length: 0

In the Docker, it could be performed by doing:

/ # wget --no-verbose --tries=1 --spider localhost:4443/_internal/healthcheck || exit 1
Connecting to localhost:4443 (127.0.0.1:4443)
remote file exists

We can implement it in Docker Compose as well:

version: '3.9'

services:
  # Adjusted for the remote container image.
  gcs:
    container_name: googlecloudstorage
    image: fsouza/fake-gcs-server
    restart: unless-stopped
    command: -scheme http
    ports:
      - 4443:4443
    volumes:
      - ./dev-data/gcs-data:/storage
    healthcheck:
      test: ['CMD-SHELL', 'wget --no-verbose --tries=1 --spider localhost:4443/_internal/healthcheck || exit 1']
      interval: 30s
      timeout: 20s
      retries: 3

Hope this helps anyone who wishes to implement the health checks!

<!-- gh-comment-id:1229111874 --> @lauslim12 commented on GitHub (Aug 27, 2022): Yep, that works properly. Thank you for adding the endpoint! Here, I will cross-post the configuration I use to perform the health check: I performed the health check on my machine by doing: ```bash akasha @ Akashas-MacBook-Pro: ~/Projects/fake-gcs-server $ curl -I -X GET localhost:4443/_internal/healthcheck HTTP/1.1 200 OK Date: Sat, 27 Aug 2022 03:17:04 GMT Content-Length: 0 ``` In the Docker, it could be performed by doing: ```bash / # wget --no-verbose --tries=1 --spider localhost:4443/_internal/healthcheck || exit 1 Connecting to localhost:4443 (127.0.0.1:4443) remote file exists ``` We can implement it in Docker Compose as well: ```yml version: '3.9' services: # Adjusted for the remote container image. gcs: container_name: googlecloudstorage image: fsouza/fake-gcs-server restart: unless-stopped command: -scheme http ports: - 4443:4443 volumes: - ./dev-data/gcs-data:/storage healthcheck: test: ['CMD-SHELL', 'wget --no-verbose --tries=1 --spider localhost:4443/_internal/healthcheck || exit 1'] interval: 30s timeout: 20s retries: 3 ``` Hope this helps anyone who wishes to implement the health checks!
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/fake-gcs-server#140
No description provided.