DEV Community

Srashti Gupta
Srashti Gupta

Posted on

πŸ›  Common CI/CD Errors in Docker + AWS ECS Deployment (and How to Fix Them)

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
Enter fullscreen mode Exit fullscreen mode

πŸ” Error: Missing Secrets or Environment Variables

Message:

MONGO_URI is undefined
Enter fullscreen mode Exit fullscreen mode

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');
Enter fullscreen mode Exit fullscreen mode

πŸ” 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
Enter fullscreen mode Exit fullscreen mode

βœ… Bonus: Use a .dockerignore File

Speed up builds and prevent accidental context issues:

node_modules
.env
.git
Enter fullscreen mode Exit fullscreen mode

🧠 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)