Containerization with Docker

Tabla de Contenidos

Containers package applications with their dependencies, making deployment consistent across environments.

Docker Basics

Installation

# Ubuntu/Debian
curl -fsSL https://get.docker.com -o get-docker.sh
sh get-docker.sh

# Arch Linux
pacman -S docker

Basic Commands

docker ps                    # Running containers
docker ps -a                 # All containers
docker images                # List images
docker pull image            # Download image
docker run image             # Run container
docker stop container        # Stop container
docker rm container          # Remove container

Dockerfile

FROM ubuntu:22.04
RUN apt-get update && apt-get install -y nginx
COPY index.html /var/www/html/
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]

Building

docker build -t myapp:latest .
docker run -p 8080:80 myapp:latest

Docker Compose

version: '3.8'
services:
  web:
    build: .
    ports:
      - "8000:80"
  db:
    image: postgres:15
    environment:
      POSTGRES_DB: mydb
docker-compose up -d
docker-compose down

Volume Management

docker volume create myvolume
docker run -v myvolume:/data container
docker run -v /host/path:/container/path container

Networking

docker network create mynetwork
docker run --network mynetwork container

Best Practices

  • Use specific image tags, not latest
  • Minimize image layers
  • Use multi-stage builds
  • Don't run as root in containers
  • Keep images small

Containers revolutionize how we deploy and manage applications.

¿Te gusta este contenido?

Si este artículo te fue útil, considera invitarme un café. ¡Tu apoyo ayuda a mantener este sitio!

Prerequisitos

Siguientes Rutas

Rutas Alternativas

Artículos Relacionados