Facing issues while deploying your Node.js app to AWS ECS with Docker and GitHub Actions? Hereβs a complete list of common CI/CD errors and easy, step-by-step solutions with clear explanations. β
π Issue & π Fix Table
π Issue | π Fix |
---|---|
β Docker build fails | β
Check Dockerfile syntax and .dockerignore context |
β Missing secrets | β Add all secrets in GitHub β Settings β Actions β Secrets |
β ECS service fails to deploy | β Double-check ECS cluster, task def, and service names |
β App crashes in ECS | β View logs under ECS β Tasks β Logs |
β Latest image not deployed | β
Use --force-new-deployment in ECS or update image tag |
π Error: Docker Build Fails
Message:
Docker build command fails, often with missing file or bad instruction errors.
Cause:
You likely forgot to copy package.json
correctly in your Dockerfile (or misplaced the order).
Fix:
COPY package*.json ./
RUN npm install
COPY . . # copy source only after dependencies
π Error: Missing Secrets or Environment Variables
Message:
MONGO_URI is undefined
Cause:
Your code references secrets/env-vars not passed along in the ECS definition.
How to Fix:
- Go to ECS β Task Definitions.
- Add required environment variables: e.g.,
MONGO_URI
,JWT_SECRET
. - (Alternatively) Use AWS Secrets Manager and reference them in the task.
π Error: ECS Fails to Deploy New Task
Messages:
npm ERR! enoent ENOENT: no such file or directory, open 'package.json'
ServiceNotFoundException
CannotPullContainerError
Cause:
Incorrect ECS cluster/service/task name in your GitHub Actions workflow, or the image/tag does not exist in ECR.
How to Fix:
- Double-check the names in your:
- ECS cluster
- ECS service
- Task definition
- Ensure the correct image tag exists in the ECR repository.
π Error: App Crashes After Deployment
Symptom:
ECS service stops immediately. No public access or 502 Bad Gateway
from load balancer.
How to Fix:
- Go to ECS β Tasks β Logs and view the error output.
- Make sure your app is listening globally, not just on
localhost
:
app.listen(3000, '0.0.0.0');
π Error: Docker Image Doesnβt Update
Cause:
Youβre using a static latest
tag and ECS believes it already deployed it.
How to Fix:
Use --force-new-deployment
to trigger ECS to re-pull the image, or update to a different tag.
- name: π Deploy to Amazon ECS
run: |
aws ecs update-service \
--cluster $ECS_CLUSTER \
--service $ECS_SERVICE \
--force-new-deployment
β
Bonus: Use a .dockerignore
File
Speed up builds and prevent accidental context issues:
node_modules
.env
.git
π§ Conclusion
CI/CD is powerful, but small misconfigurations can halt deployments. Be sure to:
- Carefully review build logs
- Monitor ECS logs
- Always verify secrets and naming
Once setup is smooth, your Dockerized Node.js app will deploy automatically to AWS ECS with every push! π
Let me know in the comments if youβd like a template for:
- GitHub Actions workflow
- Dockerfile
- AWS ECS task definition (in JSON)
Happy Deploying! π
Top comments (0)