Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question] docker v3.1.8 failed to initialize database #1091

Open
MinLancer opened this issue Sep 6, 2024 · 8 comments
Open

[Question] docker v3.1.8 failed to initialize database #1091

MinLancer opened this issue Sep 6, 2024 · 8 comments

Comments

@MinLancer
Copy link

Describe the question
docker 从 3.1.7 版本 升级 3.1.8 版本,报错无法连接mysql。一样的docker-compose和 conf.toml配置,回滚到3.1.7后正常运行。

To Reproduce

  1. 修改 docker-compose ‘image: yeelabs/yearning:v3.1.7’ 为 ‘image: yeelabs/yearning:v3.1.8’
  2. docker-compose up -d
  3. 报错如下:
    2024/09/06 16:31:29 Yearning-go/src/model/db.go:66
    yearning | [error] failed to initialize database, got error dial tcp: lookup = : no such host
    yearning | [Error] 2024-09-06 16:31:29 (Yearning-go/src/model/db.go:72) MySQL connection failed! Please check the configuration information

Expected behavior
跟3.1.7一样正常运行

Screenshots
image
image

image

Deployment
Docker

Env (please complete the following information):

  • OS: [centos 7]
  • Browser [ chrome]
  • Version [v3.1.8]
@cookieY
Copy link
Owner

cookieY commented Sep 12, 2024

init database

docker run --rm -it -p8000:8000 -e SECRET_KEY=$SECRET_KEY -e MYSQL_USER=$MYSQL_USER -e MYSQL_ADDR=$MYSQL_ADDR -e MYSQL_PASSWORD=$MYSQL_PASSWORD -e MYSQL_DB=$Yearning_DB -e Y_LANG=zh_CN yeelabs/yearning "/opt/Yearning install"

You must initialize your database in the startup container

docker run -d -it -p8000:8000 -e SECRET_KEY=$SECRET_KEY -e MYSQL_USER=$MYSQL_USER -e MYSQL_ADDR=$MYSQL_ADDR -e MYSQL_PASSWORD=$MYSQL_PASSWORD -e MYSQL_DB=$Yearning_DB -e Y_LANG=zh_CN yeelabs/yearning

@MinLancer
Copy link
Author

首先,我这个不是初始安装,而是由3.1.7升级到3.1.8的。之前3.1.7版本Yearning已经运行很长时间。数据库已经有大量数据。
然后,你提供的方案 /opt/Yearning install 是初次安装的命令,应该不适合我这个情况。不过我还是按照你的执行了,仍然报错如问题中的截图。
然后,我又执行了 Yearning migrate 命令,也是如上图的报错。
另外我的数据库是 mysql 5.7 ,不知道是否3.1.8的Yearning不支持?

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


First of all, this is not an initial installation, but an upgrade from 3.1.7 to 3.1.8. The previous 3.1.7 version of Yearning has been running for a long time. The database already has a lot of data.
Then, the solution you provided, /opt/Yearning install, is a command for initial installation and should not be suitable for my situation. However, I still followed your instructions and still got an error like the screenshot in the question.
Then, I executed the Yearning migrate command again, and the error was reported as shown above.
In addition, my database is mysql 5.7. I wonder if Yearning 3.1.8 does not support it?

@cookieY
Copy link
Owner

cookieY commented Sep 25, 2024

当你使用环境变量后 程序是不会去读取 conf.toml 里面的配置的 只会从环境变量中获取

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


When you use environment variables, the program will not read the configuration in conf.toml, but will only obtain it from the environment variables.

@dellnoantechnp
Copy link

dellnoantechnp commented Oct 9, 2024

遇到同样的问题:
在 pod 上取消了环境变量,仍然提示连接不到数据库:

2024/10/09 18:50:44 Yearning-go/src/model/db.go:66
[error] failed to initialize database, got error dial tcp: lookup = : no such host
 [Error] 2024-10-09 18:50:44 (Yearning-go/src/model/db.go:72) MySQL connection failed! Please check the configuration information

结果一看环境变量:

# echo $MYSQL_ADDR
=

Dockerfile 默认就设置了 MYSQL_ADDR 等环境变量吧:

# docker run -it --rm --name=test docker.io/yeelabs/yearning:v3.1.8 bash
0fc36c208799:/opt# env
CHARSET=UTF-8
HOSTNAME=0fc36c208799
MYSQL_DB== 
PWD=/opt
Y_LANG== zh-CN
MYSQL_PASSWORD==           <------
MYSQL_USER==               <------
HOME=/root
LANG=C.UTF-8
SECRET_KEY== dbcjqheupqjsuwsm
TERM=xterm
SHLVL=1
MYSQL_ADDR==                <------
LC_COLLATE=C
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
_=/usr/bin/env

会导致 config.tomlconf.toml 不生效。

PS:文档里写配置文件名是 config.toml,命令帮助又说的默认找 conf.toml,不知道以哪个为准,文档有点乱。


手动操作可以跑通:

# unset MYSQL_ADDR MYSQL_DB MYSQL_USER
# ./Yearning --verbose=4 install -c config.toml
# ./Yearning --verbose=4 run -c config.toml

@dellnoantechnp
Copy link

我提交了 PR 申请 #1113 ,修正了 Dockerfile 上面的一些错误,更新了文档中部分描述内容。

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


I submitted PR request #1113, fixed some errors in the Dockerfile, and updated some descriptions in the documentation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants