Welcome to from-docker-to-kubernetes

Docker Desktop & Development Environments

Learn how to use Docker Desktop for streamlined development and create consistent development environments

Docker Desktop

Docker Desktop provides an easy-to-use, integrated environment for building, sharing, and running containerized applications on Windows, macOS, and Linux. It bundles the Docker engine, CLI client, Docker Compose, Kubernetes, and other essential tools into a single application with a graphical user interface, making container development accessible to developers of all experience levels.

Getting Started with Docker Desktop

Installation

  • Platform-specific installers: Different installation packages optimized for Windows (with WSL2 integration), macOS (Intel and Apple Silicon), and Linux
  • System requirements: Minimum 4GB RAM, 2 CPU cores, and 20GB disk space; Windows 10/11 Pro/Enterprise or WSL2 on Home edition; macOS 10.15+ or Apple Silicon
  • Desktop configuration options: Customizable resources, file sharing, network settings, and Kubernetes configuration
  • Integration with operating system: Native integration with Windows, macOS, and Linux filesystems, networking, and authentication
  • Extension management: Built-in marketplace for Docker extensions to enhance functionality and workflow integration

Key Features

  • Container management UI: Intuitive graphical interface for starting, stopping, and monitoring containers
  • Image browsing and management: Visual tools for exploring, pulling, building, and cleaning up container images
  • Docker Hub integration: Seamless access to public and private repositories with credential management
  • Volume and network management: Create, configure, and monitor Docker volumes and networks through the UI
  • Integrated Kubernetes: Single-node Kubernetes cluster built-in, allowing easy switching between Docker Swarm and Kubernetes
  • Dashboard analytics: Real-time monitoring of container resource usage, logs, and health status
  • Dev Environments: Collaborative development environments that can be shared across teams

Docker Desktop Interface

# Command-line equivalents to Docker Desktop UI actions
# List containers (equivalent to Containers tab)
docker ps -a

# View container logs (equivalent to container logs view)
docker logs container_name

# View container stats (equivalent to container stats view)
docker stats container_name

Docker Desktop Settings

Resources

# Example resource allocation in settings.json
{
  "cpus": 4,                # Number of CPU cores allocated to Docker VM
  "memory": "8 GB",         # RAM allocated to Docker engine
  "swap": "1 GB",           # Additional swap space for memory-intensive operations
  "diskSize": "60 GB",      # Size of the virtual disk for container storage
  "dataFolder": "/path/to/custom/docker-data",  # Custom data location
  "memorySwap": "9 GB",     # Total memory including swap (memory + swap)
  "diskImage": "/path/to/docker-disk.raw" # Custom disk image location
}

Resource allocation directly impacts Docker performance:

  • Insufficient CPU: Slow container startup and build times
  • Limited memory: Container crashes with out-of-memory errors
  • Small disk size: "No space left on device" errors during builds
  • Appropriate resource allocation prevents performance bottlenecks

File Sharing

  • Configure shared folders: Specify which host directories are available to containers
    # In settings.json or through the UI
    "filesharingDirectories": [
      "/Users/username/projects",
      "/Volumes/data"
    ]
    
  • Access host files from containers: Mount host directories as volumes in containers
    docker run -v /Users/username/projects:/app myimage
    
  • Performance considerations: Different performance characteristics across platforms
    • Windows/WSL2: Best performance in WSL2 filesystem
    • macOS: Slower performance due to osxfs with gRPC FUSE for file sharing
    • Linux: Near-native performance with minimal overhead
  • Filesystem isolation: Control which directories are accessible to containers for security
    • Selective sharing prevents exposing sensitive host files
    • Use bind mounts for development, named volumes for production
    • Consider using delegated/cached mount options on macOS for performance

Network

  • Port forwarding: Expose container services to host network
    # Automatically forward ports or configure in docker-compose.yml
    docker run -p 8080:80 nginx  # Maps container port 80 to host port 8080
    
  • DNS configuration: Configure custom DNS servers for container resolution
    {
      "dns": ["8.8.8.8", "1.1.1.1"],
      "dns-search": ["example.com"]
    }
    
  • Proxy settings: Configure HTTP/HTTPS proxies for container internet access
    {
      "httpProxy": "http://proxy.example.com:8080",
      "httpsProxy": "http://proxy.example.com:8080",
      "noProxy": "localhost,127.0.0.1,.example.com"
    }
    
  • Network driver selection: Choose appropriate network drivers for different use cases
    • bridge: Default isolated network for containers (default)
    • host: Use host network directly (higher performance, lower isolation)
    • overlay: Multi-host networking for Swarm/Kubernetes
    • macvlan: Assign MAC addresses to containers for physical network appearance
    • none: Disable networking for maximum isolation

Docker Desktop Extensions

# Install extensions via Docker Desktop UI or CLI
docker extension install name-of-extension

# List installed extensions
docker extension ls

# Update an extension
docker extension update name-of-extension

Docker Dev Environments

Creating Dev Environments

From Git Repository

  1. Click "Create" in Dev Environments: Access the creation wizard from Docker Desktop
  2. Provide Git repository URL: Enter a Git repository that contains Docker configuration
    https://github.com/username/project.git
    
  3. Configure environment settings: Set resource limits, volume mounts, and environment variables
    # Customizable settings for the environment
    resources:
      cpus: 2
      memory: 4GB
    volumeMounts:
      - source: ~/.ssh
        target: /home/user/.ssh
        readonly: true
    
  4. Start the environment: Docker pulls the repository and builds the development container
    # Behind the scenes, Docker runs:
    git clone https://github.com/username/project.git
    docker-compose -f docker-compose.yml -f docker-compose.dev.yml up -d
    
  5. Connect via VS Code or other IDE: Open the code in your preferred editor with container integration
    # For VS Code
    code --folder-uri vscode-remote://attached-container+name=project_dev
    # Or use the "Open in VS Code" button in Docker Desktop
    

From Local Folder

  1. Select "Create From Local Folder": Use existing code on your machine
  2. Choose project directory: Select the folder containing your code
    # Docker Desktop mounts this directory into the dev environment
    /Users/username/projects/my-application
    
  3. Configure Docker Compose settings: Customize how the environment is built
    # Docker Desktop generates or uses existing docker-compose.yml
    services:
      app:
        build: .
        volumes:
          - .:/app
          - ~/.aws:/home/user/.aws:ro
        ports:
          - "3000:3000"
        environment:
          - NODE_ENV=development
    
  4. Launch the environment: Docker builds and starts the development container
    # Docker performs these operations:
    docker-compose build  # Build any custom images
    docker-compose up -d  # Start the environment
    
  5. Start development: Begin coding with host-container file synchronization
    # Changes in your local directory immediately reflect in the container
    # Example workflow:
    vim src/app.js  # Edit a file locally
    docker-compose exec app npm test  # Run tests in the container
    

docker-compose.yaml for Dev Environments

version: '3.8'
services:
  app:
    build: 
      context: .
      dockerfile: Dockerfile.dev
    volumes:
      - .:/app
      - /app/node_modules
    ports:
      - "3000:3000"
    environment:
      - NODE_ENV=development
    
  db:
    image: postgres:13
    environment:
      - POSTGRES_PASSWORD=password
      - POSTGRES_USER=user
      - POSTGRES_DB=myapp
    volumes:
      - postgres_data:/var/lib/postgresql/data
    
volumes:
  postgres_data:

Configuring Development Containers

Dockerfile for Development

FROM node:16

WORKDIR /app

# Install development dependencies
COPY package*.json ./
RUN npm install

# Keep container running
CMD ["npm", "run", "dev"]

VS Code Integration

// .devcontainer/devcontainer.json
{
  "name": "Node.js Development",
  "dockerComposeFile": "../docker-compose.yaml",
  "service": "app",
  "workspaceFolder": "/app",
  "extensions": [
    "dbaeumer.vscode-eslint",
    "esbenp.prettier-vscode"
  ],
  "settings": {
    "terminal.integrated.shell.linux": "/bin/bash"
  }
}

Sharing Dev Environments

# Export environment settings
docker dev-environments export my-project > my-project.tar.gz

# Share environment with team
# (Via Docker Hub or file sharing)

# Import shared environment
docker dev-environments import my-project.tar.gz

Multi-Container Development

Volume Mounts and Performance

Bind Mounts

  • Real-time code updates: Changes to source code are immediately visible inside containers
    # Edit code on host, container sees changes instantly
    docker run -v $(pwd)/src:/app/src node:16 npm run dev
    
  • Native filesystem access: Container processes can read/write host files directly
    volumes:
      - ./src:/app/src  # Direct mapping of source directory
      - ./config:/app/config:ro  # Read-only access to configuration
    
  • Development workflow integration: Works with IDEs, linters, and other developer tools
    # VSCode can access files while container runs the code
    volumes:
      - .:/app  # Mount entire project for IDE integration
    
  • Performance considerations per OS:
    • Windows with WSL2: Near-native performance when files are in WSL2 filesystem
    • Windows with Hyper-V: Slower performance due to filesystem translation
    • macOS: Performance penalties of 10-20x for I/O-intensive operations
    • Linux: Best performance with minimal overhead
    # macOS performance optimizations
    volumes:
      - ./src:/app/src:delegated  # Improves performance by delaying host updates
    
  • Path mapping configuration: Configure exact mapping between host and container paths
    volumes:
      # Absolute paths
      - /Users/developer/projects/myapp:/app
      # Relative paths (relative to docker-compose.yml)
      - ./logs:/app/logs
      # Home directory references
      - ~/configs:/app/configs
    

Volume Types

# Named volume (for dependencies and build artifacts)
docker run -v my_node_modules:/app/node_modules -v .:/app node:16

# Bind mount (for source code)
docker run -v $(pwd):/app -w /app node:16 npm run dev

Debugging in Docker Development Environments

# docker-compose.yaml with debugging configuration
version: '3.8'
services:
  app:
    build: .
    ports:
      - "3000:3000"
      - "9229:9229"  # Node.js debug port
    volumes:
      - .:/app
    command: npm run debug  # Script with --inspect=0.0.0.0:9229

Docker Desktop Dashboard for Development

Container Management

  • Start/stop containers
  • View container logs
  • Access container terminal
  • Container resource monitoring
  • Container restart policies

Extensions for Development

  • Database management
  • API testing
  • Container scanning
  • Code editing
  • Resource monitoring

Project Templates

CI/CD Integration

# GitHub Actions with Docker Dev Environments
name: Test in Dev Environment

on: [push, pull_request]

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      
      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v2
      
      - name: Build Dev Environment
        run: docker-compose build
      
      - name: Run Tests
        run: docker-compose run app npm test

Best Practices

Performance Optimization

  • Use multi-stage builds
  • Implement .dockerignore
  • Optimize volume mounts
  • Configure resource limits
  • Use buildkit for faster builds

Team Workflows

  • Document environment setup
  • Use version control for Docker files
  • Implement container health checks
  • Create development-specific documentation
  • Standardize port allocations

Troubleshooting

Advanced Docker Desktop Features

Kubernetes Integration

  • Enable Kubernetes in settings: Activate built-in Kubernetes cluster
    # In settings.json or through the UI
    {
      "kubernetes": {
        "enabled": true,
        "showSystemContainers": false
      }
    }
    
  • Deploy to local cluster: Test Kubernetes deployments locally before production
    # Deploy application to local Kubernetes
    kubectl apply -f kubernetes/deployment.yaml
    
    # Monitor pods
    kubectl get pods -w
    
    # Access services (automatically configured in Docker Desktop)
    curl localhost:8080
    
  • Use kubectl through Docker Desktop: Integrated kubectl without separate installation
    # Docker Desktop sets up the kubectl context automatically
    kubectl config current-context
    # docker-desktop
    
    # All standard kubectl commands work
    kubectl get nodes
    kubectl get namespaces
    kubectl describe deployment my-app
    
  • Dashboard integration: Access Kubernetes resources through Docker Desktop UI
    # The Kubernetes tab shows:
    - Deployments
    - Pods
    - Services
    - ConfigMaps
    - Secrets
    - Logs and events
    
  • Context switching: Easily switch between different Kubernetes clusters
    # Switch context
    kubectl config use-context docker-desktop
    
    # View available contexts
    kubectl config get-contexts
    
    # Docker Desktop updates its UI based on current context
    
  • Resource management: Allocate appropriate resources to Kubernetes
    // Settings.json
    {
      "kubernetes": {
        "cpus": 2,
        "memory": "4GB",
        "enabled": true
      }
    }
    

WSL 2 Integration (Windows)

  • Improved performance: Dramatically faster than legacy Hyper-V backend
    # WSL 2 backend offers near-native Linux performance
    # Build performance comparison example:
    # Legacy: docker build . -t myapp  # ~120 seconds
    # WSL 2:  docker build . -t myapp  # ~45 seconds
    
  • Linux container support: Run Linux containers natively without emulation
    # WSL 2 runs a real Linux kernel
    docker exec -it mycontainer uname -a
    # Linux containerhost 5.10.102.1-microsoft-standard-WSL2 #1 SMP...
    
  • File system access: Superior performance when files are in WSL 2 filesystem
    # Best performance with projects in WSL filesystem
    # In WSL terminal:
    cd ~/projects/myapp
    docker run -v $(pwd):/app node:16 npm run build  # Fast I/O
    
    # Windows path mounting is still supported but slower
    docker run -v /c/Users/username/projects/myapp:/app node:16 npm run build
    
  • Resource sharing: Efficient memory sharing between host and Docker
    # In .wslconfig
    [wsl2]
    memory=8GB
    processors=4
    swap=2GB
    # Docker automatically uses these resources
    
  • Terminal integration: Seamless command-line experience
    # Launch WSL terminal directly from Docker Desktop
    # Or use from Windows Terminal, with Docker context already set up
    
    # Run Docker commands directly in WSL
    wsl docker ps
    wsl docker-compose up -d
    
    # Use VSCode with WSL and Docker integration
    code --remote wsl
    
  • Distribution options: Choice of WSL distros for Docker backend
    // Settings.json
    {
      "wslEngineEnabled": true,
      "wslDistro": "Ubuntu-20.04"  // Choose specific distribution
    }