skip to Main Content

I have this docker-compose file to set up a WordPress development environment. The challenge is everything runs correctly according to the logs, but the WordPress doesn’t load over the URL: localhost:9000 as specified.

version: '3.9'
services:
  db:
    container_name: 'mysql8.0'
    image: 'mysql:8.0.32'
    volumes:
      - ./data/mysql:/var/lib/mysql
    command: mysqld --default-authentication-plugin=mysql_native_password --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
    restart: always
    tty: true
    ports:
      - 18766:3306
    expose:
      - '18766'
    environment:
      - MYSQL_ROOT_PASSWORD
      - MYSQL_DATABASE
      - MYSQL_USER
      - MYSQL_PASSWORD
    networks:
      - wp
  wordpress:
    container_name: 'wordpress-app'
    depends_on:
      - db
    image: 'wordpress:6.2.0-php8.2-fpm'
    ports:
      - 9000:80
      - 443:443
    environment:
      - WORDPRESS_DB_HOST
      - WORDPRESS_DB_USER
      - WORDPRESS_DB_PASSWORD
      - WORDPRESS_DB_NAME
      - WORDPRESS_CONFIG_EXTRA
    volumes:
      - "./wordpress:/var/www/html"
      - "./wp-content:/var/www/html/wp-content"
    networks:
      - wp
  phpmyadmin:
    depends_on:
      - db
    image: phpmyadmin:5.2.1-fpm
    restart: always
    ports:
      - 8080:80
    environment:
      - PMA_HOST
      - MYSQL_ROOT_PASSWORD
    networks:
      - wp
networks:
  wp:
    driver: bridge

The output of docker ps

CONTAINER ID   IMAGE                        COMMAND                  CREATED          STATUS         PORTS                                                                                    NAMES
4f9b98c82125   wordpress:6.2.0-php8.2-fpm   "docker-entrypoint.s…"   5 minutes ago    Up 5 minutes                                                                                            elastic_rosalind
6e17a7fddc25   phpmyadmin:5.2.1-fpm         "/docker-entrypoint.…"   33 minutes ago   Up 7 minutes   9000/tcp, 0.0.0.0:8888->80/tcp, :::8888->80/tcp                                          first-plugin-phpmyadmin-1
3bc899ca693e   wordpress:6.2.0-php8.2-fpm   "docker-entrypoint.s…"   33 minutes ago   Up 7 minutes   0.0.0.0:443->443/tcp, :::443->443/tcp, 9000/tcp, 0.0.0.0:9500->80/tcp, :::9500->80/tcp   wordpress-app
2fb6f5614931   mysql:8.0.32                 "docker-entrypoint.s…"   33 minutes ago   Up 7 minutes   18766/tcp, 33060/tcp, 0.0.0.0:18766->3306/tcp, :::18766->3306/tcp                        mysql8.0

running curl:

curl -v localhost:9500                                                                                                                                                             

*   Trying 127.0.0.1:9500...
* Connected to localhost (127.0.0.1) port 9500 (#0)
> GET / HTTP/1.1
> Host: localhost:9500
> User-Agent: curl/7.81.0
> Accept: */*
> 
* Recv failure: Connection reset by peer
* Closing connection 0
curl: (56) Recv failure: Connection reset by pee

Checking with netstat

sudo netstat -tulpn | grep LISTEN                                                                                                                                                  17:46:48
[sudo] password for davidshare: 
tcp        0      0 0.0.0.0:18766           0.0.0.0:*               LISTEN      19727/docker-proxy  
tcp        0      0 0.0.0.0:443             0.0.0.0:*               LISTEN      19901/docker-proxy  
tcp        0      0 0.0.0.0:8888            0.0.0.0:*               LISTEN      19849/docker-proxy  
tcp        0      0 0.0.0.0:9500            0.0.0.0:*               LISTEN      19868/docker-proxy  
tcp        0      0 127.0.0.1:631           0.0.0.0:*               LISTEN      1461/cupsd          
tcp        0      0 127.0.0.53:53           0.0.0.0:*               LISTEN      1233/systemd-resolv 
tcp6       0      0 :::18766                :::*                    LISTEN      19733/docker-proxy  
tcp6       0      0 :::443                  :::*                    LISTEN      19912/docker-proxy  
tcp6       0      0 :::80                   :::*                    LISTEN      1628/apache2        
tcp6       0      0 :::1716                 :::*                    LISTEN      10204/kdeconnectd   
tcp6       0      0 127.0.0.1:9614          :::*                    LISTEN      10216/java          
tcp6       0      0 ::1:631                 :::*                    LISTEN      1461/cupsd          
tcp6       0      0 :::9000                 :::*                    LISTEN      20905/php-fpm: mast 
tcp6       0      0 :::8888                 :::*                    LISTEN      19856/docker-proxy  
tcp6       0      0 :::9500                 :::*                    LISTEN      19876/docker-proxy

I have tried changing the ports.

I am not sure what the issue could be. I need help.

docker log:

docker logs wordpress-app                                                                                                                                                    

[02-Apr-2023 16:19:05] NOTICE: fpm is running, pid 1
[02-Apr-2023 16:19:05] NOTICE: ready to handle connections
[02-Apr-2023 16:35:35] NOTICE: Finishing ...
[02-Apr-2023 16:35:35] NOTICE: exiting, bye-bye!
[02-Apr-2023 16:44:32] NOTICE: fpm is running, pid 1
[02-Apr-2023 16:44:32] NOTICE: ready to handle connections

2

Answers


  1. It appears that it may be the image you are using for WordPress.

    For example, I have tried your docker-compose file, switched out to the lastest WordPress, MySQL and phpmyadmin images, and I don’t have any issues with connectivity across them.

    Also make sure to delete the data, WordPress, wp-content directories that are placed in your directory as volumes.

    Login or Signup to reply.
  2. The problem you’re facing with your configuration is that image you’re using (wordpress:6.2.0-php8.2-fpm) only expose port 9000 as a FastCGI service, not as a HTTP service. You can’t make HTTP requests to it. That’s usual behaviour of PHP FPM images.

    You need to add a webserver ( apache or nginx ) container connected to FPM service to get HTTP responses.

    Try to add this to your configuration:

    nginx:
      image: 'nginx'
      restart: unless-stopped
      container_name: 'nginx'
      ports:
        - 80:80
        - 443:443
      volumes:
        - "./wordpress:/var/www/html"
      networks:
        - wp
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search