将Wordpress网站移至Docker:建立数据库连接时出错 [英] Moving Wordpress site to Docker: Error establishing DB connection

查看:667
本文介绍了将Wordpress网站移至Docker:建立数据库连接时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用Wordpress& amp;创建新网站. Docker最近对它的工作原理有了一个合理的了解,Im现在希望将一些已建立的站点移入Docker.

Ive been making new sites with Wordpress & Docker recently and have a reasonable grasp of how it all works and Im now looking to move some established sites into Docker.

我一直在遵循本指南:

https://stephenafamo.com/blog/moving-wordpress-docker-容器/

我已经进行了所有应有的设置,但是当我转到domain.com:1234时,出现错误消息建立数据库连接时出错".我已按照建议在wp-config.php中将数据库主机"更改为"mysql",并且来自Im引入站点的所有数据库详细信息都是正确的.

I have everything setup as it should be but when I go to my domain.com:1234 I get the error message 'Error establishing a database connection'. I have changed 'DB HOST' to 'mysql' in wp-config.php as advised and all the DB details from the site Im bringing in are correct.

我已连接到mysql容器,并检查数据库是否在正确的用户那里,并且还通过mysql CLI确保pw正确.

I have attached to the mysql container and checked that the db is there and with the right user and also made sure the pw is correct via mysql CLI too.

SELinux设置为允许,我没有更改任何目录/文件所有权或权限,对于后一个目录,它们全部是755,而文件644应该是应有的.

SELinux is set to permissive and I havent changed any dir/file ownership nor permissions and for the latter dirs are all 755 and files 644 as they should be.

我应该提到数据库/数据及其下的所有内容似乎都是由用户/组"polkitd输入"而不是root拥有的.

I should mention that database/data and everything under that seem to be owned by user/group 'polkitd input' instead of root.

当我在端口1234上浏览站点时,Docker日志并没有真正告诉我很多信息,除了WP容器的500条错误消息(尽管如此).

Docker logs aren't really telling me much either apart from the 500 error messages for the WP container when I browse the site on port 1234 (as expected though).

这是docker-compose文件:

This is the docker-compose file:

version: '2'

services:
  example_db:
    image: mysql:latest
    container_name: example_db
    volumes:
      - ./database/data:/var/lib/mysql
      - ./database/initdb.d:/docker-entrypoint-initdb.d
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: password123 # any random string will do
      MYSQL_DATABASE: mydomin_db # the name of your mysql database
      MYSQL_USER: my domain_me # the name of the database user
      MYSQL_PASSWORD: password123 # the password of the mysql user

  example:
    depends_on:
      - example_db
    image: wordpress:php7.1 # we're using the image with php7.1
    container_name: example
    ports:
      - "1234:80"
    restart: always
    links:
      - example_db:mysql
    volumes:
      - ./src:/var/www/html

我非常欢迎我提出建议!

Suggestions most welcome as Im out of ideas!

推荐答案

请查看以下撰写脚本.我尝试和测试.效果很好.

Please take a look at the following compose script. I tried and tested. It works fine.

version: '2'

services:
  db:
    image: mysql:latest
    container_name: db_server
    volumes:
      - ./database/data:/var/lib/mysql
      - ./database/initdb.d:/docker-entrypoint-initdb.d
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: password123 # any random string will do
      MYSQL_DATABASE: udb_test # the name of your mysql database
      MYSQL_USER: me_prname # the name of the database user
      MYSQL_PASSWORD: password123 # the password of the mysql user

  example:
    depends_on:
      - db
    image: wordpress:php7.1 # we're using the image with php7.1
    container_name: wp-web
    environment:
      WORDPRESS_DB_HOST: db:3306
      WORDPRESS_DB_USER: me_prname
      WORDPRESS_DB_PASSWORD: password123
      WORDPRESS_DB_NAME: udb_test
    ports:
      - "1234:80"
    restart: always
    volumes:
      - ./src:/var/www/html

如果您遇到其他问题,请告诉我.

Let me know if you encounter further issues.

这篇关于将Wordpress网站移至Docker:建立数据库连接时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆