serversideup / docker-php

🐳 Production-ready Docker images for PHP. Optimized for Laravel, WordPress, and more!
https://serversideup.net/open-source/docker-php/
GNU General Public License v3.0
1.65k stars 108 forks source link

Laravel Scheduler/Queue Worker HEALTHCHECK Fails (Docs Bug?) #391

Open tsterker opened 1 month ago

tsterker commented 1 month ago

Steps To Reproduce

Outcome

What did you expect?

As per the docs it is mentioned that we are intentionally re-using the same app image:

Notice we're using the same my/laravel-app image for both the PHP and Queue services. This is a common practice to keep the image consistent.

So, I would expect that there is either

What happened instead?

If followed the docs and got an unhealthy container.

Affected Docker Images

Tested with serversideup/php:8.3-unit-v3.2.0

Anything else?

Solution / Workaround

As a quick fix, we can simply disable the healthcheck:

  task:
    build:
      context: .
    command: ["php", "/var/www/html/artisan", "schedule:work"]
+   healthcheck: { test: ['NONE'] }
    volumes:
      - .:/var/www/html

I wonder if there are somewhat clean ways to introduce a dedicated healthcheck that could properly/cleanly determine if the queue worker is healthy.

lam0819 commented 1 month ago

you save me

IgordeOliveira commented 2 weeks ago

Its happen to me in production, its possible to disable health checks without docker compose ?

jaydrogers commented 2 weeks ago

The problem

If you're using the same base image of fpm-nginx for your web and Laravel Queue (like we do), Laravel Queues do not have a health check to ensure the queue is running (unlike Horizon, which uses horizon:status

The solution

Unfortunately disabling the health check is required.

More detail

To disable a Docker healthcheck, you can use different approaches in Docker Compose and Dockerfile:

Docker Compose

You can disable the healthcheck by setting it to null:

services:
  your_service:
    image: your_image
    healthcheck:
      disable: true

Dockerfile

If you've defined a healthcheck in your Dockerfile, you can disable it by using the HEALTHCHECK NONE instruction:

# Disable healthcheck
HEALTHCHECK NONE

More detail here: https://docs.docker.com/compose/compose-file/05-services/#healthcheck

Next steps