Deploy the AWS Certified App using Docker for consistent, portable deployments across any environment.
Prerequisites
Docker Engine Version 20.10 or higher
Docker Compose Version 2.0+ (optional)
Verify Docker Installation
docker --version
# Docker version 24.0.0 or higher
docker compose version
# Docker Compose version v2.20.0 or higher
If Docker is not installed, download it from docker.com
Quick Start with Docker Hub
The fastest way to run the app is using the pre-built image from Docker Hub:
Pull the image
Download the official image: docker pull thisisrober/aws-exam-prep-app:latest
Expected output: latest: Pulling from thisisrober/aws-exam-prep-app
Digest: sha256:abc123...
Status: Downloaded newer image for thisisrober/aws-exam-prep-app:latest
Run the container
Start the container: docker run -d \
--name aws-exam-app \
-p 5173:5173 \
--restart unless-stopped \
thisisrober/aws-exam-prep-app:latest
The -d flag runs the container in detached mode (background)
Building from Source
If you want to customize the image or build from source code:
Dockerfile Overview
The application uses a multi-stage build for optimal image size:
# Stage 1: Build
FROM node:18-alpine AS builder
WORKDIR /app
# Copy package files
COPY package*.json ./
# Install dependencies
RUN npm ci
# Copy application files
COPY . .
# Build the application
RUN npm run build
# Stage 2: Runtime
FROM node:18-alpine
WORKDIR /app
# Install serve to host the built app
RUN npm install -g serve
# Copy built application from builder stage
COPY --from=builder /app/dist ./dist
# Create non-root user for security
RUN addgroup -g 1001 -S nodejs && \
adduser -S nodejs -u 1001
USER nodejs
# Expose port
EXPOSE 5173
# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
CMD node -e "require('http').get('http://localhost:5173', (r) => {if (r.statusCode !== 200) throw new Error(r.statusCode)})"
# Start the application
CMD [ "serve" , "-s" , "dist" , "-l" , "5173" ]
Build Your Own Image
Clone the repository
git clone https://github.com/thisisrober/aws-certified-app.git
cd aws-certified-app
Build the Docker image
docker build -t aws-exam-app:custom .
The build process:
Installs dependencies with npm ci
Builds the production bundle with npm run build
Creates a lightweight runtime image
Copies only the built files
The build typically takes 2-5 minutes depending on your system.
Run your custom image
docker run -d \
--name aws-exam-app \
-p 5173:5173 \
aws-exam-app:custom
Docker Compose Deployment
For easier management and configuration, use Docker Compose:
docker-compose.yml
The project includes a docker-compose.yml file:
version : '3.8'
services :
app :
build :
context : .
dockerfile : Dockerfile
container_name : aws-exam-app
ports :
- "5173:5173"
environment :
- NODE_ENV=production
restart : unless-stopped
healthcheck :
test : [ "CMD" , "node" , "-e" , "require('http').get('http://localhost:5173', (r) => {if (r.statusCode !== 200) throw new Error(r.statusCode)})" ]
interval : 30s
timeout : 10s
retries : 3
start_period : 5s
networks :
- app-network
networks :
app-network :
driver : bridge
Deploy with Docker Compose
Build from source
Use Docker Hub image
# Build and start the services
docker compose up -d --build
# View logs
docker compose logs -f
# Stop the services
docker compose down
Container Management
Common Docker Commands
Container Lifecycle
Monitoring
Inspection
Shell Access
# Start the container
docker start aws-exam-app
# Stop the container
docker stop aws-exam-app
# Restart the container
docker restart aws-exam-app
# Remove the container
docker rm aws-exam-app
# Remove the container (force)
docker rm -f aws-exam-app
Configuration Options
Port Mapping
Change the host port while keeping container port 5173:
# Run on port 8080
docker run -d -p 8080:5173 --name aws-exam-app thisisrober/aws-exam-prep-app:latest
# Access at http://localhost:8080
Environment Variables
Pass environment variables to the container:
docker run -d \
--name aws-exam-app \
-p 5173:5173 \
-e NODE_ENV=production \
thisisrober/aws-exam-prep-app:latest
Resource Limits
Limit CPU and memory usage:
docker run -d \
--name aws-exam-app \
-p 5173:5173 \
--memory= "512m" \
--cpus= "0.5" \
thisisrober/aws-exam-prep-app:latest
Restart Policies
unless-stopped
always
on-failure
Restart unless manually stopped: docker run -d --restart unless-stopped aws-exam-app
Always restart (even after reboot): docker run -d --restart always aws-exam-app
Restart only on failures: docker run -d --restart on-failure:3 aws-exam-app
Health Checks
The Docker image includes a built-in health check:
# Check health status
docker inspect --format= '{{json .State.Health}}' aws-exam-app | jq
Health check configuration:
Interval : 30 seconds
Timeout : 10 seconds
Start Period : 5 seconds
Retries : 3 attempts
The health check makes an HTTP request to http://localhost:5173 and verifies a 200 status code.
Troubleshooting
Container exits immediately
If you see “port is already allocated”: # Find what's using port 5173
lsof -i :5173 # macOS/Linux
netstat -ano | findstr :5173 # Windows
# Use a different port
docker run -d -p 8080:5173 --name aws-exam-app thisisrober/aws-exam-prep-app:latest
Cannot connect to Docker daemon
Ensure Docker is running: # Check Docker status
docker info
# Start Docker Desktop (if installed)
# Or start Docker service
sudo systemctl start docker # Linux
If pulling from Docker Hub fails:
Check your internet connection
Verify the image name is correct
Try with explicit tag:
docker pull thisisrober/aws-exam-prep-app:latest
If behind a proxy, configure Docker:
# Create/edit ~/.docker/config.json
{
"proxies" : {
"default" : {
"httpProxy" : "http://proxy:port",
"httpsProxy" : "http://proxy:port"
}
}
}
Build fails with memory error
Increase Docker memory limit: Docker Desktop :
Open Settings → Resources
Increase Memory to at least 2GB
Click Apply & Restart
Linux :# Build with resource limits
docker build --memory=2g -t aws-exam-app .
Security Best Practices
Always follow security best practices when deploying containers:
Non-root User The image runs as user nodejs (UID 1001), not root
Minimal Base Image Uses node:18-alpine for a small attack surface
Health Checks Built-in health monitoring for container orchestration
Multi-stage Build Separates build and runtime for smaller images
Production Considerations
Use specific image tags
Instead of latest, use version tags: docker pull thisisrober/aws-exam-prep-app:v1.0.0
Set up reverse proxy
Use Nginx or Traefik for HTTPS and load balancing
Configure monitoring
Set up container monitoring with Prometheus or similar tools
Implement logging
Forward logs to a centralized logging system
Next Steps
Production Deployment Learn about production optimization and best practices
Local Development Set up a local development environment