This is my CDK code
const laravelCommand = [
"php",
"artisan",
"migrate"
]
taskDefinition.addContainer(`${projectName}-${imageName}-container-${env}`, {
containerName: `${projectName}-${imageName}-container-${env}`,
image: ecs.ContainerImage.fromEcrRepository(props.laravelApiEcr, 'latest'),
logging: laravelApiLogDriver,
environment: {
...envValues.environmentVariables,
},
portMappings: [
{
containerPort: 80,
hostPort: 80,
protocol: ecs.Protocol.TCP
}
],
command: laravelCommand,
})
When I comment my command command: laravelCommand,, then my task working perfectlly, but command added It will be stoped exit code 0
The log is only 'Nothing to migrate'
Why add laravel command to my ecs task then it will be auto stoped after the command excuted?
As mark-b said in replies, your command
php artisan migrateruns migrations and stop. If you want to run webserver you have to launch a webserver launch command instead of launching migrations. For example you can add an entrypoint to your dockerfile to run the migration and an ECS command to start the webserver.As a testing purpose you can replace your current command by
php artisan serve --port=80and see what happens. Normally it should fire up the built-in server and your task should keep running.Be sure to not use this php built-in server for production, instead use Nginx for production.