-1

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?

  • 1
    What would you expect to happen? It says nothing to migrate - and what then? Stopping seems reasonable. – luk2302 Aug 16 '23 at 15:05
  • Yes, I want the web server still running but the task auto stopped afther that command. When I comment out the command, my web server running normally – Nguyen Kokoro Aug 16 '23 at 15:27
  • 1
    You gave it a command to migrate and stop. The command no longer includes running the server. You need to update the command to migrate, then run the server. – Mark B Aug 16 '23 at 16:09

1 Answers1

0

As mark-b said in replies, your command php artisan migrate runs 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=80 and 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.

fred
  • 26
  • 2