skip to Main Content

i try to use docker for use wordpress with https, but that not work,

i have the message :

wordpress | MySQL Connection Error: (2002) Connection refused

 version: "3.8"
services:

    db:
        image: mysql:5.7
        volumes:
             - db_data:/var/lib/mysql
        restart: always
        environment:
            MYSQL_ROOT_PASSWORD: somewordpress
            MYSQL_DATABASE: wordpress
            MYSQL_USER: wordpress
            MYSQL_PASSWORD: wordpress

    wordpress:
        container_name: wordpress
        image: wordpress:php7.4-apache
        restart: always
        stdin_open: true
        tty: true
        environment:
            WORDPRESS_DB_HOST: db:3306
            WORDPRESS_DB_USER: wordpress
            WORDPRESS_DB_PASSWORD: wordpress
            WORDPRESS_DB_NAME: wordpress
        volumes:
            - ./wordpress:/var/www/html
       
    nginx:
        container_name: nginx
        image: nginx:latest
        restart: unless-stopped
        ports:
            - 80:80
            - 443:443
        volumes:
            - ./nginx/conf:/etc/nginx/conf.d

2

Answers


  1. I had the same problem today and after lots of unsuccessful attempts, I think adding expose helped :

    db:
      image: mysql:5.7
      volumes:
        - db_data:/var/lib/mysql
      restart: always
      environment:
        MYSQL_ROOT_PASSWORD: somewordpress
        MYSQL_DATABASE: wordpress
        MYSQL_USER: wordpress
        MYSQL_PASSWORD: wordpress
      expose:
        -"3306"
    

    Reference : https://docs.docker.com/compose/compose-file/#expose

    Login or Signup to reply.
  2. firstly, your title is "how to use wp with nginx" but in your docker compose file, you are clearly pulling a wordpress:apache image.
    secondly, you can delete the whole content related to nginx since that container runs alone and outside the scope of your wordpress.

    now, that you only have wordpress and db as services in your yml file (which is how it should be), you must add a ports directive to wordpress:

        ports:
            - 80:80
    

    And finally, for the containers to be able to resolve their ips within the same network, you need to add this at the end of your yml file:

    volumes:
      wordpress:
      db:
    

    Now this will ensure you’re running a wordpress with a db, and the wordpress image runs apache (which is httpd, not nginx).

    Thirdly, if you’re not satisfied with httpd and want an nginx container, you’ll need to look for a wordpress image on hub.docker.com that runs on nginx.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search