docker exploration

@amitmund July 10, 2026

Docker Quick Learning Notes

1. What is Docker?

  • Platform for developing, shipping, and running applications in containers
  • Containers are lightweight, standalone packages that include everything needed to run software.

  • Benefits:

    • Consistency across environments
    • Process isolation
    • Easy scalability
    • Faster deployment and development

2. Core Concepts

Images

  • Read-only templates used to create containers
  • Built in layers (each instruction creates a new layer)
  • Examples: ubuntu:22.04, nginx:latest
  • Built from Dockerfiles

Containers

  • Running instances of images
  • Isolated from host system and other containers
  • Ephemeral by default (data lost when stopped unless persisted)
  • Created from images

Dockerfile

  • Build script containing instructions for creating Docker images
  • Common instructions:
    • FROM - Specify base image
    • RUN - Execute commands during build
    • COPY/ADD - Copy files from host to container
    • CMD - Default command when container runs
    • ENTRYPOINT - Fixed executable for container
    • EXPOSE - Document which ports are intended to be published
    • ENV - Set environment variables
    • WORKDIR - Set working directory for subsequent instructions
    • VOLUME - Create mount point for external volumes

Volumes

  • Persistent storage solution for Docker containers
  • Data survives container removal and restarts
  • Shared between host and containers
  • Types:
    • Named volumes - Managed by Docker (docker volume create)
    • Bind mounts - Direct host filesystem paths
    • tmpfs mounts - Stored in host memory only

Networking

  • Enables communication between containers and external networks
  • Default network drivers:
    • bridge - Default private network for containers
    • host - Share host's network namespace
    • none - Isolated, no networking
  • Container-to-container communication

3. Essential Commands

Image Management

# Search for images on Docker Hub
docker search <image-name>

# Pull image from registry
docker pull <image-name:tag>

# List all local images
docker images

# Remove unused images
docker rmi <image-id-or-name>

# Build image from Dockerfile
docker build -t <name:tag> .

Essential Commands

Image Management

docker build -t myapp:1.0 .      # Build image from Dockerfile
docker pull nginx:latest         # Pull image from registry
docker images                    # List local images
docker rmi image_id              # Remove image
docker tag src:tag dest:tag      # Tag an image

Container Operations

docker run -d -p 80:80 --name web nginx   # Run container
docker start/stop/restart container_name  # Manage container state
docker ps -a                               # List all containers
docker rm container_name                   # Remove container
docker logs container_name                 # View container logs
docker exec -it container_name bash        # Access running container

System & Cleanup

docker system df                  # Show disk usage
docker system prune               # Remove unused data
docker volume ls                  # List volumes
docker network ls                 # List networks

Dockerfile Example

# Base image
FROM node:18-alpine

# Set working directory
WORKDIR /app

# Copy package files
COPY package*.json ./

# Install dependencies
RUN npm ci --only=production

# Copy application code
COPY . .

# Expose port
EXPOSE 3000

# Start command
CMD ["node", "server.js"]

Docker Compose Basics

version: '3.8'
services:
  web:
    build: .
    ports:
      - "80:3000"
    volumes:
      - ./src:/app/src
    environment:
      - NODE_ENV=production

  db:
    image: postgres:15
    volumes:
      - pgdata:/var/lib/postgresql/data
    environment:
      - POSTGRES_PASSWORD=secret

volumes:
  pgdata:

Commands:

docker-compose up -d     # Start services
docker-compose down      # Stop services
docker-compose logs      # View logs
docker-compose build     # Rebuild images

Best Practices

Use .dockerignore to exclude unnecessary files
Multi-stage builds to reduce image size
Pin image versions (e.g., node:18 not node:latest)
Run as non-root user in containers
Use volumes for persistent data
Minimize layers by combining RUN commands
Scan images for vulnerabilities

Quick Tips

docker run --rm - auto-remove container after exit
docker exec -it container sh - lightweight alternative to bash
docker cp container:/path /local - copy files from container
docker stats - real-time resource usage monitoring

0 Likes
23 Views
0 Comments

Filters

No filters available for this view.

Reset All