Reputation: 185
I had Next-Js application which I was containerizing and deploying it in AWS Fargate.
Below is my dockerfile
#Base Image
FROM node:18-alpine
ARG ENV=$ENV
RUN mkdir -p /usr/app/
WORKDIR /usr/app/
COPY . .
RUN ls -l
RUN npm install
RUN npm run build-qa
EXPOSE 3000
CMD ["npm", "start-qa"]
And here is my ECS Task Defination
{
"taskDefinitionArn": "arn:aws:ecs:region:**********:task-definition/NextJs-task:6",
"containerDefinitions": [
{
"name": "NextJs-container",
"image": "**********.dkr.ecr.region.amazonaws.com/next-js-app:latest",
"cpu": 1024,
"portMappings": [
{
"containerPort": 3000,
"hostPort": 3000,
"protocol": "tcp"
}
],
"essential": true,
"environment": [
{
"name": "ENV",
"value": "qa"
}
],
"mountPoints": [],
"volumesFrom": [],
"logConfiguration": {
"logDriver": "awslogs",
"options": {
"awslogs-create-group": "true",
"awslogs-group": "/ecs/NextJs",
"awslogs-region": "region",
"awslogs-stream-prefix": "ecs"
}
}
}
],
"family": "NextJs-task",
"taskRoleArn": "arn:aws:iam::**********:role/ecsTaskExecutionRole",
"executionRoleArn": "arn:aws:iam::**********:role/ecsTaskExecutionRole",
"networkMode": "awsvpc",
"revision": 6,
"volumes": [],
"status": "ACTIVE",
"requiresAttributes": [
{
"name": "com.amazonaws.ecs.capability.logging-driver.awslogs"
},
{
"name": "ecs.capability.execution-role-awslogs"
},
{
"name": "com.amazonaws.ecs.capability.ecr-auth"
},
{
"name": "com.amazonaws.ecs.capability.docker-remote-api.1.19"
},
{
"name": "com.amazonaws.ecs.capability.task-iam-role"
},
{
"name": "ecs.capability.execution-role-ecr-pull"
},
{
"name": "com.amazonaws.ecs.capability.docker-remote-api.1.18"
},
{
"name": "ecs.capability.task-eni"
},
{
"name": "com.amazonaws.ecs.capability.docker-remote-api.1.29"
}
],
"placementConstraints": [],
"compatibilities": [
"EC2",
"FARGATE"
],
"requiresCompatibilities": [
"FARGATE"
],
"cpu": "2048",
"memory": "4096",
"registeredAt": "**************",
"registeredBy": "arn:aws:sts::**********:assumed-role/aws-sre/-------------",
}
When running a task the fargate was giving error as
To see a list of supported npm commands, run:
npm help
Unknown command: "start-qa"
Did you mean one of these?
npm start # Start a package
npm run start-qa # run the "start-qa" package script
npm run start-uat # run the "start-uat" package script
I was building my docker image with following command. I have faced similar issue is AWS Apprunner too.
docker build --build-arg ENV=$ENV -t next-js-app .
Was passing the ENV from Jenkins job parameter
Upvotes: 0
Views: 288
Reputation: 200436
This error has nothing to do with Fargate, ECS, or any sort of limitation around "ENV Specific Builds". If you took the same docker image and ran it locally, you would see the same error message.
The error is telling you it doesn't understand what npm start-qa
is, and event suggesting to you that you should be doing npm run start-qa
instead.
You need to change the last line in your Dockerfile to this:
CMD ["npm", "run", "start-qa"]
Upvotes: 1