Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docker on localhost - problem with wordpress cron - Failed to connect to local.domain port 80: Connection refused #75

Open
grzesiek1owline opened this issue Jul 15, 2021 · 3 comments

Comments

@grzesiek1owline
Copy link

Codebase

Built-in vanilla WordPress

Host OS

Ubuntu 20.04

Docker info output

Client:
 Context:    default
 Debug Mode: false
 Plugins:
  app: Docker App (Docker Inc., v0.9.1-beta3)
  buildx: Build with BuildKit (Docker Inc., v0.5.1-docker)
  scan: Docker Scan (Docker Inc., v0.8.0)

Server:
 Containers: 66
  Running: 6
  Paused: 0
  Stopped: 60
 Images: 63
 Server Version: 20.10.7
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  Native Overlay Diff: true
  userxattr: false
 Logging Driver: json-file
 Cgroup Driver: cgroupfs
 Cgroup Version: 1
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
 Swarm: inactive
 Runtimes: io.containerd.runc.v2 io.containerd.runtime.v1.linux runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: d71fcd7d8303cbf684402823e425e9dd2e99285d
 runc version: b9ee9c6314599f1b4a7f497e1f1f856fe433d3b7
 init version: de40ad0
 Security Options:
  apparmor
  seccomp
   Profile: default
 Kernel Version: 5.8.0-59-generic
 Operating System: Ubuntu 20.04.2 LTS
 OSType: linux
 Architecture: x86_64
 CPUs: 16
 Total Memory: 31.23GiB
 Name: owline-Lenovo-Legion-5-15ARH05
 ID: GRKT:CPZT:P2NZ:KMMP:6EHO:ZOUM:ULZ4:RMLD:5KAA:VXIR:AQ7Q:BA4F
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 Registry: https://index.docker.io/v1/
 Labels:
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Live Restore Enabled: false

I used this a set of docker images to run wordpress on localhost: https://github.com/wodby/docker4wordpress I have a problem with cURL command when i run this tool from php files or from php container. cURL works only when i run it from nginx command line. How to config docker-compose to run cURL and repair wordpress cron. My config:

docker-compose

version: "3"

services:
  mariadb:
    image: wodby/mariadb:$MARIADB_TAG
    container_name: "${PROJECT_NAME}_mariadb"
    stop_grace_period: 30s
    environment:
      MYSQL_ROOT_PASSWORD: $DB_ROOT_PASSWORD
      MYSQL_DATABASE: $DB_NAME
      MYSQL_USER: $DB_USER
      MYSQL_PASSWORD: $DB_PASSWORD
    volumes:
#    - ./mariadb-init:/docker-entrypoint-initdb.d # Place init .sql file(s) here.
    - ./db:/var/lib/mysql # I want to manage volumes manually.

  php:
    image: wodby/wordpress-php:$PHP_TAG
    container_name: "${PROJECT_NAME}_php"
    environment:
      PHP_SENDMAIL_PATH: /usr/sbin/sendmail -t -i -S mailhog:1025
      DB_HOST: $DB_HOST
      DB_USER: $DB_USER
      DB_PASSWORD: $DB_PASSWORD
      DB_NAME: $DB_NAME
      PHP_FPM_USER: wodby
      PHP_FPM_GROUP: wodby
#      # Read instructions at https://wodby.com/docs/stacks/wordpress/local#xdebug
      PHP_XDEBUG: 1
      PHP_XDEBUG_MODE: debug
      PHP_IDE_CONFIG: serverName=PHPSTORM
      PHP_XDEBUG_IDEKEY: "PHPSTORM"
      PHP_XDEBUG_CLIENT_HOST: 172.17.0.1 # Linux
#      PHP_XDEBUG_CLIENT_HOST: host.docker.internal # Docker 18.03+ Mac/Win
#      PHP_XDEBUG_CLIENT_HOST: 10.0.75.1 # Windows
      PHP_XDEBUG_LOG: /tmp/php-xdebug.log
    volumes:
    - ./web:/var/www/html:cached
## Alternative for macOS users: Mutagen https://wodby.com/docs/stacks/wordpress/local#docker-for-mac
#    - mutagen:/var/www/html
#    # For XHProf and Xdebug profiler traces
#    - files:/mnt/files

  crond:
    image: wodby/wordpress-php:$PHP_TAG
    container_name: "${PROJECT_NAME}_crond"
    environment:
      CRONTAB: "5,10,15,20,25,35,45,55 * * * * wp cron event run --due-now --path=/var/www/html"
    command: sudo -E LD_PRELOAD=/usr/lib/preloadable_libiconv.so crond -f -d 0
    volumes:
    - ./web:/var/www/html:cached

  nginx:
    image: wodby/nginx:$NGINX_TAG
    container_name: "${PROJECT_NAME}_nginx"
    depends_on:
    - php
    environment:
      NGINX_STATIC_OPEN_FILE_CACHE: "off"
      NGINX_ERROR_LOG_LEVEL: debug
      NGINX_BACKEND_HOST: php
      NGINX_VHOST_PRESET: wordpress
      #NGINX_SERVER_ROOT: /var/www/html/subdir
    volumes:
    - ./web:/var/www/html:cached
## Alternative for macOS users: Mutagen https://wodby.com/docs/stacks/wordpress/local#docker-for-mac
#    - mutagen:/var/www/html
    labels:
    - "traefik.http.routers.${PROJECT_NAME}_nginx.rule=Host(`${PROJECT_BASE_URL}`)"

  mailhog:
    image: mailhog/mailhog
    container_name: "${PROJECT_NAME}_mailhog"
    labels:
    - "traefik.http.services.${PROJECT_NAME}_mailhog.loadbalancer.server.port=8025"
    - "traefik.http.routers.${PROJECT_NAME}_mailhog.rule=Host(`mailhog.${PROJECT_BASE_URL}`)"

  adminer:
    container_name: "${PROJECT_NAME}_adminer"
    image: wodby/adminer:$ADMINER_TAG
    environment:
##      # For PostgreSQL:
##      ADMINER_DEFAULT_DB_DRIVER: pgsql
      ADMINER_DEFAULT_DB_HOST: $DB_HOST
      ADMINER_DEFAULT_DB_NAME: $DB_NAME
    labels:
    - "traefik.http.routers.${PROJECT_NAME}_adminer.rule=Host(`adminer.${PROJECT_BASE_URL}`)"

  pma:
    image: phpmyadmin/phpmyadmin
    container_name: "${PROJECT_NAME}_pma"
    environment:
      PMA_HOST: $DB_HOST
      PMA_USER: $DB_USER
      PMA_PASSWORD: $DB_PASSWORD
      PHP_UPLOAD_MAX_FILESIZE: 1G
      PHP_MAX_INPUT_VARS: 1G
    labels:
    - "traefik.http.routers.${PROJECT_NAME}_pma.rule=Host(`pma.${PROJECT_BASE_URL}`)"

and traefik docker-compose

version: '3'

services:
  traefik:
    image: traefik:v2.0
    command: --api.insecure=true --providers.docker
    networks:
    - talenti
    ports:
    - '80:80'
    - '8080:8080'
    volumes:
    - /var/run/docker.sock:/var/run/docker.sock
    restart: always

networks:
  talenti:
    external:
      name: talenti_default
owline@owline-Lenovo-Legion-5-15ARH05:~$ docker network ls
NETWORK ID     NAME                          DRIVER    SCOPE
b9309fcd7b7c   bridge                        bridge    local
427502257d25   host                          host      local
18418489a0d5   none                          null      local
985e9f39dab9   talenti_default               bridge    local
@pjv
Copy link

pjv commented Aug 13, 2021

Try adding a network alias to the traefik service definition like so:

traefik:
  image: traefik:v2.0
  container_name: "${PROJECT_NAME}_traefik"
  command: --api.insecure=true --providers.docker
  ports:
  - '8000:80'
#    - '8080:8080' # Dashboard
  volumes:
    - /var/run/docker.sock:/var/run/docker.sock
  networks:
    default:
      aliases:
        - ${PROJECT_NAME}.${PROJECT_BASE_URL}

For me, this fixed the loopback error and rest api error reported on the "site health" page in wordpress.

@csandanov this is a potential fix for numerous obscure loopback and rest API related issues that have been reported over time here.

@audetcameron
Copy link

Try adding a network alias to the traefik service definition like so:

traefik:
  image: traefik:v2.0
  container_name: "${PROJECT_NAME}_traefik"
  command: --api.insecure=true --providers.docker
  ports:
  - '8000:80'
#    - '8080:8080' # Dashboard
  volumes:
    - /var/run/docker.sock:/var/run/docker.sock
  networks:
    default:
      aliases:
        - ${PROJECT_NAME}.${PROJECT_BASE_URL}

For me, this fixed the loopback error and rest api error reported on the "site health" page in wordpress.

@csandanov this is a potential fix for numerous obscure loopback and rest API related issues that have been reported over time here.

I think this just ended up breaking things for me...
unless I'm doing something wrong, when I add the alias mysite.docker.localhost (and the domain and docker.localhost pointed in my host file to 127.0.0.1 ) I just get a 404.
I think because the ailas and main one are competing or something? 🤷
Would love to figure out loopbacks.

@pjv
Copy link

pjv commented Nov 17, 2023

@audetcameron indeed that alias seems not to work anymore. At the time I wrote the original post it did solve both the loopback and the rest api errors for me, but now using that alias those errors are back. I get the same errors either with or without the alias now. back to square one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants