Matt Hale
Director, School of Interdisciplinary Informatics
Director, NebraskaCYBER
Associate Professor of Cybersecurity
CYBR 8470 - Secure Web Development
slides.com/matthale/cybr8470-containers
slides.com/matthale/cybr8470-containers
slides.com/matthale/cybr8470-containers
Definition
Lightweight, standalone packages encapsulating an application and its dependencies.
slides.com/matthale/cybr8470-containers
slides.com/matthale/cybr8470-containers
Microservices Architecture: Breaking down applications into smaller, manageable services.
DevOps and CI/CD Pipelines: Streamlining development, testing, and deployment processes.
Hybrid and Multi-Cloud Deployments: Ensuring consistency across different cloud providers and on-premises environments.
slides.com/matthale/cybr8470-containers
Consistency Across Environments:
Eliminates "it works on my machine" issues.
Resource Efficiency:
Consume fewer resources than VMs.
Rapid Deployment:
Facilitate continuous integration and deployment (CI/CD).
Simplified Maintenance:
Easy to update or replace containers without affecting the host.
slides.com/matthale/cybr8470-containers
|
Feature |
Containers |
Virtual Machines (VMs) |
|---|---|---|
|
Isolation Level |
OS-level isolation |
Hardware-level isolation |
|
Resource Efficiency |
Lightweight, share host OS |
Heavier, each VM includes a full OS |
|
Startup Time |
Seconds |
Minutes |
|
Portability |
Highly portable across environments |
Less portable, dependent on hypervisor |
slides.com/matthale/cybr8470-containers
slides.com/matthale/cybr8470-containers
Enhanced Portability: Containers ensure applications run consistently across various environments.
Improved Scalability: Easily scale applications horizontally by adding more container instances.
Resource Efficiency: Optimize resource usage, reducing costs and improving performance.
Faster Deployment: Accelerate the development lifecycle with quicker deployment and rollback capabilities.
slides.com/matthale/cybr8470-containers
Most widely used containerization platform.
Key Components:
slides.com/matthale/cybr8470-containers
Docker Engine
Docker Compose
Docker CLI:
Docker Desktop:
slides.com/matthale/cybr8470-containers
Integrations with Orchestration Tools
Docker Ecosystem and Community
slides.com/matthale/cybr8470-containers
Portability and Platform Support
Security Features
slides.com/matthale/cybr8470-containers
Assess Current Applications:
Containerize Dependencies:
Create Dockerfile:
Define Environment: Specify the base image, install dependencies, and set environment variables.
Copy Application Code: Add the application source code into the image, or use a bound volume if you need it to change without rebuilding.
Configure Startup Commands: Define how the application should start within the container.
slides.com/matthale/cybr8470-containers
simple dockerfile example, src: https://docs.docker.com/get-started/workshop/02_our_app/
4. Build Docker Images:
docker build command to create an image from the Dockerfile.5. Test Containers Locally:
docker run with necessary configurations for testing.6. Deploy to Production:
slides.com/matthale/cybr8470-containers
slides.com/matthale/cybr8470-containers
slides.com/matthale/cybr8470-containers
Start Small: Begin with non-critical components to understand the process.
Automate Builds: Use CI/CD tools for building and testing Docker images.
Use Multi-Stage Builds: Optimize image sizes and enhance security.
Implement Monitoring and Logging: Utilize tools like Prometheus and the ELK stack for performance and logs.
slides.com/matthale/cybr8470-containers
Definition: Managing and provisioning infrastructure through machine-readable configuration files.
Advantages:
Automated, consistent, and scalable infrastructure management.
slides.com/matthale/cybr8470-containers
img credit: https://blog.sparkfabrik.com/en/infrastructure-as-code-what-is-it-and-its-benefits
Version Control: Track and manage changes using systems like Git.
Repeatability: Easily reproduce environments, reducing drift.
Scalability: Automate infrastructure provisioning to meet demand.
Collaboration: Shared configuration files facilitate teamwork.
Automation: Integrate with CI/CD pipelines for deployment and updates.
slides.com/matthale/cybr8470-containers
Role of Docker in IaC: Define and manage application environments programmatically.
Key Tools:
slides.com/matthale/cybr8470-containers
Define Multi-Container Applications:
All dependencies specified in a single docker-compose.yml file.
Components:
slides.com/matthale/cybr8470-containers
Define Services:
Specify Docker image/build context, ports, environment variables, dependencies.
Configure Networks:
Create custom networks for secure communication.
Manage Volumes:
Persist data across container restarts.
Deploy with a Single Command:
docker-compose up -d
slides.com/matthale/cybr8470-containers
View Logs:
docker-compose logs -f
Stop Containers:
docker-compose down
Remove Containers, Networks, and Volumes:
docker-compose down -v
slides.com/matthale/cybr8470-containers
Store Configuration Files:
Keep Dockerfile and docker-compose.yml in version control (e.g., Git).
Advantages:
slides.com/matthale/cybr8470-containers
IaC allows for seamless deployment using CI/CD (continuous integration / continuous deployment) pipelines
Pipeline Phases:
slides.com/matthale/cybr8470-containers
Least Privilege: Define minimal permissions for services and components.
Secrets Management: Use environment variables or secret management tools for sensitive data.
Image Scanning: Regularly scan Docker images for vulnerabilities.
Immutable Infrastructure: Avoid manual changes to deployed infrastructure to maintain consistency.
slides.com/matthale/cybr8470-containers
slides.com/matthale/cybr8470-containers
sudo apt update
sudo apt upgrade -y
curl -fsSL https://deb.nodesource.com/setup_14.x | sudo -E bash -
sudo apt-get install -y nodejs
node -v
npm -v
slides.com/matthale/cybr8470-containers
sudo apt-get install -y postgresql postgresql-contrib
sudo systemctl start postgresql
sudo systemctl enable postgresql
sudo -i -u postgres
createdb app_db
createuser admin -P
psql
GRANT ALL PRIVILEGES ON DATABASE app_db TO admin;
\q
exit
slides.com/matthale/cybr8470-containers
git clone https://github.com/username/my-node-app.git
cd my-node-app
npm install
touch .env
Add to .env:
NODE_ENV=production
PORT=8080
DATABASE_URL=postgres://admin:secret@localhost:5432/app_db
slides.com/matthale/cybr8470-containers
npm start
Navigate to http://localhost:8080
slides.com/matthale/cybr8470-containers
| Pros | Cons |
|---|---|
| Direct access to host resources | Potential for dependency conflicts |
| Simpler for small, single applications | Harder to replicate environments |
| Easier debugging on the host | Scaling requires manual intervention |
slides.com/matthale/cybr8470-containers
git clone https://github.com/username/my-node-app.git
cd my-node-app
FROM node:14-alpine
WORKDIR /usr/src/app
COPY package*.json ./
RUN npm install --production
COPY . .
EXPOSE 8080
CMD ["node", "app.js"]
slides.com/matthale/cybr8470-containers
docker-compose.yml:
version: '3'
services:
web:
build: .
ports:
- "8080:8080"
environment:
- NODE_ENV=production
- DATABASE_URL=postgres://admin:secret@db:5432/app_db
depends_on:
- db
db:
image: postgres:13
environment:
- POSTGRES_USER=admin
- POSTGRES_PASSWORD=secret
- POSTGRES_DB=app_db
volumes:
- db-data:/var/lib/postgresql/data
volumes:
db-data:
slides.com/matthale/cybr8470-containers
docker-compose up -d --build
docker-compose ps
Navigate to http://localhost:8080
slides.com/matthale/cybr8470-containers
| Pros | Cons |
|---|---|
| Consistent environments across all stages | Initial learning curve with Docker tools |
| Easy to scale horizontally | Additional layer may obscure debugging |
| Isolation of dependencies | Potential overhead in resource-constrained environments |
| Simplified deployment and rollback | Requires Docker and Docker Compose on all environments |
slides.com/matthale/cybr8470-containers
| Aspect | Native Installation | Dockerized Installation |
|---|---|---|
| Setup Complexity | Manual installation of dependencies | Automated through Dockerfiles and Compose |
| Environment Consistency | Prone to differences across environments | Ensures identical environments across stages |
| Scalability | Manual scaling; complex for multiple instances | Easy horizontal scaling with orchestration |
| Isolation | Limited; potential dependency conflicts | High; containers encapsulate all dependencies |
| Deployment Speed | Slower; individual environment configuration | Rapid deployment using pre-built images |
| Resource Utilization | Significant overhead from OS if using VMs | Efficient with shared kernel and isolated containers |
| Maintenance | Manual updates and dependency management | Automated builds and updates via Docker pipelines |
| Portability | Less portable; environment-specific configurations | Highly portable; runs anywhere Docker is supported |
slides.com/matthale/cybr8470-containers
©2024 Matthew L. Hale
University of Nebraska at Omaha
Associate Professor, Cybersecurity
Director, School of Interdisciplinary Informatics
Director, NebraskaCYBER
mlhale@unomaha.edu
twitter: X: @mlhale
slides.com/matthale/cybr8470-containers