This repository contains a containerized Node JS application ready for deployment on AWS EC2. Follow this step-by-step guide to get your application up and running in a Docker container.
- AWS Account
- Docker Hub Account
- Basic understanding of Docker and AWS
- SSH client installed on your local machine
# Launch an Ubuntu EC2 instance on AWS
# Configure security groups for ports:
- SSH (22)
- HTTP (80)
- HTTPS (443)
- Go to AWS Console → EC2 → Security Groups
- Select your instance's security group
- Add inbound rules:
- Type: Custom TCP - Port: 8000 - Source: Your IP address or 0.0.0.0/0 (for public access) - Description: Node JS application port
- Click "Save rules"
⚠️ Security Note: Using 0.0.0.0/0 opens access to everyone. For production, always restrict to specific IP ranges.
# Update package lists
sudo apt update
# Install Docker
sudo apt install docker.io
# Add user to docker group to avoid permission issues
sudo usermod -aG docker ubuntu
# Verify Docker installation
docker run hello-world
💡 Note: If you encounter permission denied errors, log out and log back in for group changes to take effect.
# Clone your repository
git clone <your-repository-url>
# Navigate to project directory
cd <project-directory>
# Build Docker image
docker build -t <image-name>:<tag> .
# Verify image creation
docker images
# Run Docker container
docker run -p 3000:8000 <image-name>:<tag>
# Login to Docker Hub
docker login
# Tag your image
docker tag <local-image-name>:<tag> <dockerhub-username>/<repository-name>:<tag>
# Push to Docker Hub
docker push <dockerhub-username>/<repository-name>:<tag>
-
Check running containers:
docker ps
-
View application logs:
docker logs <container-id>
-
Access your application:
http://<ec2-public-ip>:8000
-
Permission Denied
- Solution: Run
sudo usermod -aG docker ubuntu
and restart your session
- Solution: Run
-
Port Already in Use
- Solution: Change the port mapping or stop the conflicting service
-
Container Exits Immediately
- Solution: Check logs using
docker logs <container-id>
- Solution: Check logs using
-
Cannot Access Application
- Solution: Verify security group inbound rules allow traffic on port 8000
- Check if container is running using
docker ps
- Ensure EC2 instance public IP is correct
- Keep your Docker images updated
- Use specific tags instead of
latest
- Implement proper security groups in AWS:
- Only open necessary ports
- Restrict IP ranges when possible
- Regularly review and update security rules
- Never commit sensitive data to your repository
Feel free to submit issues and pull requests to improve this deployment guide.
This project is licensed under the MIT License - see the LICENSE file for details.
If you have any questions or need help, please:
- Open an issue in this repository
- Contact the development team
- Check our documentation
⭐ Don't forget to star this repository if you found it helpful!