我最近一直在使用Wordpress和Docker创建新站点,并且对它的工作方式有一个合理的了解,我现在正寻求将一些已建立的站点移入Docker。
我一直在遵循本指南:
https://stephenafamo.com/blog/moving-wordpress-docker-container/
我已经进行了应有的一切设置,但是当我转到domain.com:1234时,收到错误消息“建立数据库连接时出错”。我已按照建议在wp-config.php中将“数据库主机”更改为“mysql”,并且来自Im引入站点的所有数据库详细信息都是正确的。
我已经连接到mysql容器,并检查数据库是否在正确的用户那里,并且还通过mysql CLI确保pw正确。
SELinux设置为允许,我没有更改任何目录/文件所有权或权限,对于后一个目录,它们全部是755,而文件644是应有的。
编辑:我应该提到数据库/数据及其下的所有内容似乎都由用户/组“polkitd输入”而非root拥有。
当我在端口1234上浏览站点时(尽管如此),Docker日志并没有真正告诉我太多信息,除了WP容器的500条错误消息。
这是docker-compose文件:
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
建议最受欢迎,因为我没有想法!
最佳答案
请看下面的撰写脚本。我尝试和测试。它工作正常。
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
如果您遇到其他问题,请告诉我。
关于mysql - 将Wordpress网站移至Docker:建立数据库连接时出错,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/52186125/