AWS Docker and Elastic Beanstalk Deployment Guide

Welcome to this comprehensive guide on deploying a containerized application using Docker and AWS Elastic Beanstalk! πŸš€ Let’s dive in and explore each step in detail.

Table of Contents


Install Docker

Step 1: Install Docker Desktop

πŸ’‘ What is Docker Desktop? Docker Desktop is a user-friendly tool for managing Docker containers. It simplifies the process of building, testing, and deploying applications.

  • Download Docker Desktop from the official website.
  • Install Docker Desktop on your machine.
  • Verify Installation by running docker --version in the terminal.

πŸ“ Ensure Docker is correctly installed and configured to avoid issues later.

Step 2: Run a Pre-Built Container Image

  • Run Nginx Container:
    docker run -d -p 80:80 nginx
    
  • Access the Nginx Welcome Page at http://localhost.

πŸ’‘ What is Nginx? Nginx is a high-performance web server used to serve web content. It’s commonly used in containerized environments.


Build Your Custom Image

Step 1: Create a Dockerfile

Create a Dockerfile with the following content:

FROM nginx:latest
COPY index.html /usr/share/nginx/html/
EXPOSE 80

πŸ’‘ Understanding Dockerfile Instructions

  • FROM nginx:latest uses the latest Nginx image as a base.
  • COPY index.html /usr/share/nginx/html/ replaces the default Nginx HTML file.
  • EXPOSE 80 makes port 80 available for connections.

Step 2: Create Your HTML Content

Create index.html:

<!doctype html>
<html>
  <head>
    <title>My Web App</title>
  </head>
  <body>
    <h1>Hello from YOURNAME's custom Docker image!</h1>
  </body>
</html>

πŸ’‘ Customize Your Webpage Replace YOURNAME with your name to personalize the message.

Step 3: Build Your Docker Image

Build the Docker Image:

docker build -t my-web-app .

πŸ“ Ensure all files are in the correct directory and the Dockerfile is properly configured.

Step 4: Run Your Custom Image

Run the Custom Image:

docker run -d -p 80:80 my-web-app

Verify Deployment by accessing http://localhost in your browser.

⚠️ Port Conflicts Ensure no other services are using port 80 to avoid conflicts.


Deploy to Elastic Beanstalk

Step 1: Set Up Elastic Beanstalk

Create an Elastic Beanstalk Application:

  • Navigate to the Elastic Beanstalk console.
  • Choose Create Application and follow the prompts.
  • Select Docker as the platform.

πŸ’‘ What is Elastic Beanstalk? Elastic Beanstalk simplifies the deployment of applications by managing the underlying infrastructure.

Step 2: Upload Your Application Code

Prepare Your Application:

  • Create a ZIP file containing your Dockerfile and index.html.
  • Upload the ZIP File in Elastic Beanstalk.

πŸ“ Ensure files are at the root level of the ZIP to avoid deployment issues.

Step 3: Configure and Deploy

Configure Environment Settings:

  • Set the environment type to Single Instance.
  • Ensure the correct platform version and branch are selected.
  • Deploy your application and access it via the provided domain link.

⚠️ Resource Costs Remember to terminate environments and delete resources when they are no longer needed to avoid unnecessary costs.


Delete Resources

Step 1: Terminate Elastic Beanstalk Environment

  • Navigate to your environment in the Elastic Beanstalk console.
  • Select Terminate Environment and confirm the action.

πŸ’‘ Cleanup is Crucial Properly deleting resources ensures you don’t incur unexpected charges.

Step 2: Remove Docker Containers

List all containers:

docker ps -a

Stop and remove containers:

docker stop <container_id>
docker rm <container_id>

πŸ“ Replace <container_id> with the actual ID of your container.

Step 3: Delete S3 Buckets

  • Navigate to the S3 Console.
  • Delete buckets associated with your Elastic Beanstalk application.

⚠️ Bucket Deletion Ensure you have the necessary permissions and confirm deletions to prevent data loss.


Conclusion

Congrats! You’ve successfully deployed a containerized application to AWS Elastic Beanstalk. Remember to clean up resources to manage costs and maintain security best practices. Happy coding! πŸŽ‰

πŸ“§ Contact

For questions or feedback, reach out:

πŸ“¨ Email: projects@briankimemia.is-a.dev 🌐 Portfolio: Brian Kimemia GitHub: BrianKN019


Thank you for exploring this project! Let’s innovate and build secure AWS solutions together. πŸš€