【发布时间】:2026-01-30 02:35:01
【问题描述】:
我有一个 dockerized AdonisJs 应用程序,我正尝试在 ECS (AWS) 上部署它。我设法部署了映像,但现在我不知道如何在部署时运行迁移。
通过学习 Udemy 课程,我看到有人必须做同样的事情,但使用 laravel。在 Dockerfile 中,他没有运行 CMD ['artisan','serve'],而是创建了一个 start.sh 脚本,他在其中启动应用程序,将其置于后台,运行迁移,然后将应用程序放回后台。这是脚本:
#!/bin/sh
# turn on bash's job control
set -m
# Start the primary process and put it in the background
php-fpm &
# Start the helper process
php artisan migrate
# now we bring the primary process back into the foreground
# and leave it there
fg %1
我尝试对 Adonis 做同样的事情,这是我的脚本(许多版本之一):
#!/bin/sh
# turn on bash's job control
set -m
# Start the primary process and put it in the background
adonis serve &
# Start the helper process
adonis migration:run
# now we bring the primary process back into the foreground
# and leave it there
fg %1
但我总是会出错。例如:
- 服务器启动,但迁移未运行,因为 adonis 无法连接到数据库。我不知道如何调试它,因为如果我只是正常启动应用程序,Adonis 可以完美连接到数据库。
- (我只在本地尝试过)服务器启动,迁移运行,但是服务器进程没有进入前台,所以应用程序没有真正启动(
curl localhost它给了我curl: (7) Failed to connect to localhost port 80: Connection refused)我也不能用 ctrl+c 停止服务器,我必须找到 docker 容器并停止容器。 这是控制台向我显示的内容:
SERVER STARTED
info: serving app on http://0.0.0.0:80
Nothing to migrate
您能帮我创建一个执行此操作的脚本吗?
EDIT1:我注意到即使我创建了一个只有“adonis serve”的脚本,它仍然无法正常工作,所以也许这不是通过脚本启动服务器的正确方法?
【问题讨论】:
-
运行迁移:
node ace migration:run --force& 启动服务器:node server.js -
试过了,但是迁移没有退出/完成。
-
我注意到,即使我创建了一个只有“adonis serve”的脚本,它仍然无法正常工作,所以也许这不是通过脚本启动服务器的正确方法?
-
迁移未退出/完成 -> 检查数据库是否已启动并可访问。检查您的迁移文件
-
运行服务器:
node server.js
标签: bash docker dockerfile amazon-ecs adonis.js