我正在尝试在本地计算机上使用Docker设置Mura CMS。 MYSQL数据库似乎无法正常工作。
我正在使用docker-compose up
命令。我一直在尝试以下示例:
https://github.com/blueriver/docker-muracms/tree/master/examples/blueriver-muracms-mysql
version: '3.3'
services:
muracms:
image: blueriver/muracms:latest
depends_on:
- svc_muradb
environment:
MURA_ADMIN_USERNAME: admin
MURA_ADMIN_PASSWORD: 5trongP@55w0rd
MURA_ADMINEMAIL: youremail@domain.com
MURA_APPRELOADKEY: appreload
MURA_DATASOURCE: dsn_muracms
MURA_DATABASE: muradb
MURA_DBTYPE: mysql
MURA_DBUSERNAME: root
MURA_DBPASSWORD: 5trongP@55w0rd
MURA_DBHOST: svc_muradb
MURA_DBPORT: 3306
MURA_SITEIDINURLS: "false"
MURA_INDEXFILEINURLS: "true"
MURA_TESTBOX: "true"
MURA_USESSL: "false"
volumes:
- ./www/modules:/var/www/modules
- ./www/plugins:/var/www/plugins
- ./www/sites:/var/www/sites
- ./www/themes:/var/www/themes
ports:
- "8888:8888"
# DB
svc_muradb:
image: mysql:latest
environment:
MYSQL_DATABASE: muradb
MYSQL_ROOT_PASSWORD: 5trongP@55w0rd
volumes:
- vol_muradb:/var/lib/mysql
ports:
- "5001:3306"
# Mounts
volumes:
vol_muradb:
浏览localhost:8888时看到以下错误消息:
500 Error
Could not create connection to database server.
Code:0
Type:database
lucee.runtime.exp.DatabaseException: Could not create connection to database server.
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:425)
at com.mysql.jdbc.Util.getInstance(Util.java:408)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:918)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:897)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:886)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:860)
答案 0 :(得分:0)
这是因为muracms
开始时,svc_muradb
仍未完成其初始化。
depends_on
仅确保svc_muradb
首先开始,然后再启动muracms
。但是启动过程svc_muradb
是异步的。因此,在svc_muradb
准备就绪之前,您的muracms
很有可能已经想要连接数据库。
official guide中记录了此问题,建议您为svc_muradb
命令编写包装。
就像下面,我仅举一个例子:
docker-compose.yml:
version: "2"
services:
web:
build: .
ports:
- "80:8000"
depends_on:
- "db"
command: ["./wait-for-it.sh", "db:5432", "--", "python", "app.py"]
db:
image: postgres
wait-for-it.sh:
#!/bin/sh
# wait-for-postgres.sh
set -e
host="$1"
shift
cmd="$@"
until PGPASSWORD=$POSTGRES_PASSWORD psql -h "$host" -U "postgres" -c '\q'; do
>&2 echo "Postgres is unavailable - sleeping"
sleep 1
done
>&2 echo "Postgres is up - executing command"
exec $cmd
通过上述解决方法,Web容器将运行wait-for-it.sh
,首先它将尝试链接其依赖项容器db:5432
,只有在确认可以使用psql client
链接到数据库之后,然后它将运行真实的命令python app.py
。
就您而言,您需要进行与mysql client test
相关的更改,然后一切正常。