Tag: Docker

  • Fixing Loopback Request Issue in WordPress in Docker

    If Site Health shows “Your site could not complete a loopback request” (or The REST API encountered an error) when running WordPress in Docker behind a reverse proxy (e.g., Caddy), the culprit is often that extra_hosts entry pointing to a container IP that changes on restart. Which is always as a solution to solve the loopback issue.

    The fix (use a Docker network alias)

    Let Docker’s built-in DNS keep things in sync by giving your proxy container a network alias that matches your site’s domain. Then all other containers resolve the alias to the current IP automatically. Would be a better solution than specifying the internal IP for PHP container:

    services:
      caddy:
        # ...your existing caddy config...
        networks:
          default:
            aliases:
              - example.com

    Now remove any extra_hosts lines you previously added to other services (like php).

    Apply & verify

    # Recreate containers
    docker compose up -d
    
    # From the php container, confirm the alias resolves
    docker compose exec php getent hosts example.com
    
    # (Optional) Hit wp-cron directly
    docker compose exec php curl -I https://example.com/wp-cron.php?doing_wp_cron=1

    Return to Tools → Site Health and re-check: loopback should pass, and scheduled tasks will run normally.

  • Self-hosted Sentry Postgres Database Cleanup

    The official documentation is event wrong, when you execute the following command:

    docker compose run --rm -T postgres bash -c "apt update && apt install -y --no-install-recommends postgresql-14-repack && su postgres -c 'pg_repack -E info -t nodestore_node'"

    You will get the following error:

    Removing obsolete dictionary files:
    ERROR: could not connect to database: connection to server on socket "/var/run/postgresql/.s.PGSQL.5432" failed: No such file or directory
    	Is the server running locally and accepting connections on that socket?

    This issue has been tracked on GitHub but does not have a solution. Here’s my solution:

    docker compose -f docker-compose.yml -f docker-compose.override.yml --env-file /srv/git/sentry/.env.custom exec -T postgres bash -c "
      apt update && apt install -y --no-install-recommends postgresql-14-repack &&
      su postgres -c 'psql -c \"CREATE EXTENSION IF NOT EXISTS pg_repack;\"' &&
      su postgres -c 'pg_repack -E info -t nodestore_node'
    "

  • Running HomeBridge on Docker without Host Network Mode | Dev With Imagination

    There is a docker image available, but the setup instructions for this require the container to be ran with the “host” networking mode. The primary reason for this appears to be to allow an Avahi daemon to run in the container and be able to answer responses to mDNS requests, which requires the container to be in the same local network subnet as the device performing the lookup.

    Source: Running HomeBridge on Docker without Host Network Mode | Dev With Imagination

  • Docker Mounted Volumes Permission Issues with Nginx and PHP-FPM

    Prerequisites:

    • Official Nginx alpine Docker image
    • Official PHP Docker (Debian) image with fpm tags

    Get currenty PHP-FPM running user info:

    $ docker exec php_container_name id www-data
    uid=33(www-data) gid=33(www-data) groups=33(www-data)

    Change the owner of your existing mounted volume:

    chown 33:33 -R /srv/www