docker-compose wordpress mysql connection refused

后端 未结 6 890
轮回少年
轮回少年 2021-01-01 12:52

I\'ve created a small docker-compose.yml which used to work like a charm to deploy small WordPress instances. It looks like this:

wordpress:
  i         


        
相关标签:
6条回答
  • 2021-01-01 13:01

    I too had troubles here. I was using docker-compose to set up multiple wordpress websites on a single (micro) Virtual Private Server, including phpmyadmin and jwilder/nginx-proxy as a controller.

    $ docker logs XXXX will help indicate areas of concern. In my case, the MariaDB databases would keep restarting all the time.

    It turns out that all that stuff just wouldn't fit on a micro 512M Single CPU service. I never received error messages that told me directly that size was an issue, but after adding things up, I realized that when all the databases were starting up, I was running out of memory. An upgrade to 1Gb, 1 CPU service worked just fine.

    0 讨论(0)
  • 2021-01-01 13:01

    I was using your docker-compose.yml, had the same problem. Just restarting didn't fix. After nearly an hour of researching the logs, I found the problem was: wordpress service started connecting mysql service before it had fully started. Simply adding depends_on won't help.Docker Compose wait for container X before starting Y

    the work around could be start the db server before Up. When it has fully started, run docker-compose up. Or just use external service.

    0 讨论(0)
  • 2021-01-01 13:01

    In my case, I'm using Mysql (not MariaDb) but I had the same problem. After upgrading the MySQL version, it's works fine.

    You can see my open source docker-compose configuration: https://github.com/rimiti/wordpress-dockerized-environment

    0 讨论(0)
  • 2021-01-01 13:04

    To fix this issue the first thing to do is:

    Add the following code to wordpress & database containers (in the docker-compose file):

    restart: unless-stopped
    

    This will make sure you Database is started and intialized before wordpress container trying to connect to it. Then restart docker engine

    sudo restart docker
    

    or (for ubuntu 15+)

    sudo service docker restart 
    

    Here the full configuration that worked for me, to setup wordpress with MariaDB:

    version: '2'
    
    services:
      wordpress:
        image: wordpress:latest
        links:
          - database:mariadb
        environment:
          - WORDPRESS_DB_USER=wordpress
          - WORDPRESS_DB_NAME=mydbname
          - WORDPRESS_TABLE_PREFIX=ab_
          - WORDPRESS_DB_PASSWORD=password
          - WORDPRESS_DB_HOST=mariadb
          - MYSQL_PORT_3306_TCP=3306
        restart: unless-stopped
        ports:
          - "test.dev:80:80"
        working_dir: /var/www/html
        volumes:
         - ./wordpress/:/var/www/html/
      database:
       image: mariadb:latest
       environment:
         - MYSQL_ROOT_PASSWORD=password
         - MYSQL_DATABASE=mydbname
         - MYSQL_USER=wordpress
         - MYSQL_PASSWORD=password
       restart: unless-stopped
       ports:
         - "3306:3306"
    
    0 讨论(0)
  • 2021-01-01 13:18

    The reason for this behaviour probably was related to a recent kernel and docker update. I recognized several other connection issues in other docker-compose setups. Therefore I restarted the server (not just the docker service) and didn't have had any issues like this ever since.

    0 讨论(0)
  • 2021-01-01 13:25

    I had almost same problem, but just restarting the Wordpress container saved me:

    $ docker restart wordpress
    

    I hope this help many people.

    0 讨论(0)
提交回复
热议问题