Follow these steps to efficiently build, push, and deploy a Dockerized application to AWS Elastic Beanstalk using Amazon Elastic Container Registry (ECR):
1. Build the Docker Image
Use Docker Compose to build the application image locally:
bash
docker compose up --build
- This command creates or rebuilds services defined in the
docker-compose.ymlfile, ensuring all dependencies are built and updated.
2. Authenticate Docker to AWS ECR
Before pushing the Docker image, authenticate Docker to the target ECR registry:
bash
aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin 985542660797.dkr.ecr.us-east-1.amazonaws.com
- Replace
us-east-1with your AWS region as needed. - Replace the account ID and registry URL if using a different AWS account or repository.
- This command securely logs Docker into the AWS ECR registry.
3. Push the Docker Image to ECR
Push the built Docker image to the ECR repository:
bash
docker push 985542660797.dkr.ecr.us-east-1.amazonaws.com/edgarallan/wesapi-staging
- Ensure the image tag matches what was built in the previous steps.
- This makes the image available for deployment in AWS services.
4. Deploy to AWS Elastic Beanstalk
Deploy the latest image to an AWS Elastic Beanstalk environment:
bash
eb deploy
- The
eb deploycommand uploads the current application version (configurations and Docker image) to the Elastic Beanstalk environment. - Ensure the Elastic Beanstalk CLI is set up and configured for the correct environment.
Best Practices
- Always verify AWS credentials and permissions before starting the deployment process.
- Use version tags for Docker images to avoid confusion and ensure deployment consistency.
- Monitor the deployment status in the AWS Elastic Beanstalk console for confirmation and troubleshooting.
For more information, see the official documentation: