!=
+
+
sqlite
+
+
graphql
+
+
+
+
+
swc
+
+
+
+
+
+
+
+
css
+
+
+
nvim
|>
c#
marko
+
0b
+
=>
preact
delphi
+
+
+
tls
++
+
+
+
arch
+
wsl
weaviate
+
+
+
htmx
+
vue
+
λ
+
vscode
+
+
saml
+
+
+
+
+
+
+
0b
zorin
https
+
+
pandas
+
strapi
js
+
+
+
+
==
bbedit
nvim
numpy
+
+
bun
astro
Back to Blog
🐳 Setting Up Development Containers on Alpine Linux: Simple Guide
Alpine Linux Docker Containers

🐳 Setting Up Development Containers on Alpine Linux: Simple Guide

Published Jun 18, 2025

Easy tutorial for creating development containers on Alpine Linux. Perfect for beginners with step-by-step instructions for Docker, dev environments, and containerized workflows.

18 min read
0 views
Table of Contents

🐳 Setting Up Development Containers on Alpine Linux: Simple Guide

Creating development containers on Alpine Linux makes coding portable and consistent! 💻 This guide shows you how to build development environments inside containers. Let’s containerize your development workflow! 😊

🤔 What are Development Containers?

Development containers are isolated environments that contain everything needed to develop, build, and run applications.

Development containers are like:

  • 📝 Portable development offices - Take your entire setup anywhere
  • 🔧 Pre-configured workspaces - Everything ready to start coding
  • 💡 Isolated sandboxes - Keep different projects separate and clean

🎯 What You Need

Before we start, you need:

  • ✅ Alpine Linux running on your computer
  • ✅ Root access or sudo permissions
  • ✅ At least 4GB of free disk space
  • ✅ Basic understanding of containers and development

📋 Step 1: Install Docker and Container Tools

Install Docker Engine

Let’s install Docker for container development! 😊

What we’re doing: Installing Docker Engine and container development tools.

# Update package list
apk update

# Install Docker
apk add docker docker-compose

# Install additional container tools
apk add git curl wget

# Start Docker service
rc-service docker start
rc-update add docker boot

# Add user to docker group (replace 'username' with your username)
adduser $USER docker

# Apply group changes (you may need to log out and back in)
newgrp docker

# Test Docker installation
docker --version
docker-compose --version

# Run Docker hello-world test
docker run hello-world

What this does: 📖 Installs Docker and sets up container development environment.

Example output:

✅ (1/4) Installing docker (24.0.5-r1)
✅ (2/4) Installing docker-compose (2.20.2-r0)
✅ (3/4) Installing git (2.40.1-r0)
✅ (4/4) Installing curl (8.2.1-r0)
✅ Docker version 24.0.5, build ced0996
✅ Docker Compose version v2.20.2
✅ Hello from Docker!

What this means: Your container development environment is ready! ✅

💡 Important Tips

Tip: Development containers keep your host system clean! 💡

Warning: Container images can use significant disk space! ⚠️

🛠️ Step 2: Create Basic Development Containers

Build a Node.js Development Container

Now let’s create a development container for Node.js! 😊

What we’re doing: Creating a containerized Node.js development environment.

# Create development projects directory
mkdir -p ~/dev-containers/nodejs-dev
cd ~/dev-containers/nodejs-dev

# Create Dockerfile for Node.js development
cat > Dockerfile << 'EOF'
# Use Alpine Linux as base image
FROM node:18-alpine

# Set working directory
WORKDIR /workspace

# Install development tools
RUN apk add --no-cache \
    git \
    bash \
    curl \
    wget \
    vim \
    nano \
    openssh-client \
    build-base \
    python3 \
    py3-pip

# Install global Node.js development tools
RUN npm install -g \
    @angular/cli \
    @vue/cli \
    create-react-app \
    typescript \
    ts-node \
    nodemon \
    eslint \
    prettier

# Create development user
RUN addgroup -g 1000 developer && \
    adduser -D -s /bin/bash -u 1000 -G developer developer

# Set up SSH directory for git operations
RUN mkdir -p /home/developer/.ssh && \
    chown -R developer:developer /home/developer/.ssh && \
    chmod 700 /home/developer/.ssh

# Install VS Code extensions helper
RUN npm install -g @vscode/vsce

# Set default user
USER developer

# Set default shell
ENV SHELL=/bin/bash

# Expose common development ports
EXPOSE 3000 4200 8080 8000 5000

# Keep container running
CMD ["/bin/bash"]
EOF

# Create docker-compose.yml for easy management
cat > docker-compose.yml << 'EOF'
version: '3.8'

services:
  nodejs-dev:
    build: .
    container_name: nodejs-dev-container
    volumes:
      - ./workspace:/workspace
      - ~/.ssh:/home/developer/.ssh:ro
      - ~/.gitconfig:/home/developer/.gitconfig:ro
    ports:
      - "3000:3000"
      - "4200:4200"
      - "8080:8080"
      - "8000:8000"
      - "5000:5000"
    environment:
      - NODE_ENV=development
    working_dir: /workspace
    tty: true
    stdin_open: true
    networks:
      - dev-network

networks:
  dev-network:
    driver: bridge
EOF

# Create workspace directory
mkdir -p workspace

# Build the development container
echo "🏗️  Building Node.js development container..."
docker-compose build

# Start the development environment
echo "🚀 Starting Node.js development container..."
docker-compose up -d

# Test the container
echo "🧪 Testing Node.js development environment:"
docker-compose exec nodejs-dev node --version
docker-compose exec nodejs-dev npm --version

Code explanation:

  • FROM node:18-alpine: Uses official Node.js Alpine image
  • WORKDIR /workspace: Sets working directory for development
  • EXPOSE: Opens ports for development servers
  • volumes: Mounts local directories into container

Expected Output:

✅ Node.js development container built successfully
✅ Container started: nodejs-dev-container
✅ Node.js: v18.17.1
✅ npm: 9.6.7
✅ Development environment ready!

What this means: Great job! Your Node.js development container is running! 🎉

🎮 Let’s Test Development Container!

Time for hands-on practice! This is the fun part! 🎯

What we’re doing: Creating a sample project inside the development container.

# Access the development container
echo "🔧 Accessing Node.js development container:"
docker-compose exec nodejs-dev bash

# Inside the container, create a sample React app
npx create-react-app sample-app
cd sample-app

# Start the development server
npm start &

# Test if the app is accessible
curl -s http://localhost:3000 | head -10

# Exit container
exit

# Check container status
echo ""
echo "📊 Container Status:"
docker-compose ps

# View container logs
echo ""
echo "📋 Container Logs:"
docker-compose logs nodejs-dev | tail -10

You should see:

🔧 Accessing Node.js development container:
✅ Created React app: sample-app
✅ Development server started on port 3000
📊 Container Status:
  nodejs-dev-container   Up   0.0.0.0:3000->3000/tcp
📋 Container Logs:
  webpack compiled successfully

Awesome work! 🌟

📊 Development Container Types

Container TypeBase ImageBest ForTools Included
🔧 Node.jsnode:alpine✅ Web developmentnpm, React, Angular, Vue
🛠️ Pythonpython:alpine✅ Data science, APIspip, Django, Flask, Jupyter
🎯 Gogolang:alpine✅ System programmingGo toolchain, modules
💾 Javaopenjdk:alpine✅ Enterprise appsMaven, Gradle, Spring
⚡ PHPphp:alpine✅ Web applicationsComposer, Laravel, Symfony

🛠️ Step 3: Create Multi-Language Development Environment

Build Universal Development Container

What we’re doing: Creating a container with multiple programming languages and tools.

# Create universal development environment
mkdir -p ~/dev-containers/universal-dev
cd ~/dev-containers/universal-dev

# Create comprehensive Dockerfile
cat > Dockerfile << 'EOF'
# Use Alpine Linux as base
FROM alpine:latest

# Install system packages
RUN apk add --no-cache \
    bash \
    git \
    curl \
    wget \
    vim \
    nano \
    openssh-client \
    build-base \
    cmake \
    make \
    autoconf \
    automake \
    libtool \
    pkgconfig

# Install Node.js and npm
RUN apk add --no-cache nodejs npm yarn

# Install Python
RUN apk add --no-cache python3 py3-pip python3-dev

# Install Go
RUN apk add --no-cache go

# Install Java
RUN apk add --no-cache openjdk11-jdk maven

# Install PHP
RUN apk add --no-cache php81 php81-cli php81-common

# Install Rust
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
ENV PATH="/root/.cargo/bin:${PATH}"

# Install Docker CLI (for Docker-in-Docker scenarios)
RUN apk add --no-cache docker-cli

# Install development tools
RUN npm install -g \
    typescript \
    @angular/cli \
    @vue/cli \
    create-react-app \
    eslint \
    prettier

RUN pip3 install \
    django \
    flask \
    fastapi \
    jupyter \
    pandas \
    numpy \
    requests

# Install Go tools
RUN go install golang.org/x/tools/gopls@latest
RUN go install github.com/go-delve/delve/cmd/dlv@latest

# Create development user
RUN addgroup -g 1000 developer && \
    adduser -D -s /bin/bash -u 1000 -G developer developer

# Set up workspace
WORKDIR /workspace
RUN chown developer:developer /workspace

# Switch to developer user
USER developer

# Set environment variables
ENV JAVA_HOME=/usr/lib/jvm/java-11-openjdk
ENV GOPATH=/home/developer/go
ENV PATH=$PATH:$GOPATH/bin:/root/.cargo/bin

# Expose common development ports
EXPOSE 3000 4200 8080 8000 5000 9000

CMD ["/bin/bash"]
EOF

# Create docker-compose for universal development
cat > docker-compose.yml << 'EOF'
version: '3.8'

services:
  universal-dev:
    build: .
    container_name: universal-dev-container
    volumes:
      - ./workspace:/workspace
      - ~/.ssh:/home/developer/.ssh:ro
      - ~/.gitconfig:/home/developer/.gitconfig:ro
      - /var/run/docker.sock:/var/run/docker.sock
    ports:
      - "3000:3000"
      - "4200:4200"
      - "8080:8080"
      - "8000:8000"
      - "5000:5000"
      - "9000:9000"
    environment:
      - NODE_ENV=development
      - PYTHONPATH=/workspace
    working_dir: /workspace
    tty: true
    stdin_open: true
    privileged: true
    networks:
      - dev-network

networks:
  dev-network:
    driver: bridge
EOF

# Create workspace directory
mkdir -p workspace

# Build universal development container
echo "🏗️  Building universal development container..."
docker-compose build

echo "✅ Universal development environment ready!"

What this does: Creates a comprehensive development environment with multiple languages! 🌟

Create Development Container Templates

What we’re doing: Building reusable templates for different development scenarios.

# Create template management script
cat > ~/bin/dev_container_manager.sh << 'EOF'
#!/bin/bash

echo "🐳 Development Container Manager"
echo "==============================="

TEMPLATES_DIR=~/dev-containers

create_template() {
    local template_name="$1"
    local language="$2"
    
    echo "🏗️  Creating $language development template: $template_name"
    
    mkdir -p "$TEMPLATES_DIR/$template_name"
    cd "$TEMPLATES_DIR/$template_name"
    
    case "$language" in
        "python")
            cat > Dockerfile << 'DOCKERFILE_EOF'
FROM python:3.11-alpine

WORKDIR /workspace

RUN apk add --no-cache git bash vim curl wget build-base

RUN pip install \
    django \
    flask \
    fastapi \
    jupyter \
    pandas \
    numpy \
    requests \
    pytest \
    black \
    flake8

RUN addgroup -g 1000 developer && \
    adduser -D -s /bin/bash -u 1000 -G developer developer

USER developer

EXPOSE 8000 5000 8888

CMD ["/bin/bash"]
DOCKERFILE_EOF
            ;;
            
        "go")
            cat > Dockerfile << 'DOCKERFILE_EOF'
FROM golang:1.21-alpine

WORKDIR /workspace

RUN apk add --no-cache git bash vim curl wget build-base

RUN go install golang.org/x/tools/gopls@latest
RUN go install github.com/go-delve/delve/cmd/dlv@latest

RUN addgroup -g 1000 developer && \
    adduser -D -s /bin/bash -u 1000 -G developer developer

USER developer

ENV GOPATH=/home/developer/go
ENV PATH=$PATH:$GOPATH/bin

EXPOSE 8080 9000

CMD ["/bin/bash"]
DOCKERFILE_EOF
            ;;
            
        "rust")
            cat > Dockerfile << 'DOCKERFILE_EOF'
FROM rust:alpine

WORKDIR /workspace

RUN apk add --no-cache git bash vim curl wget build-base

RUN rustup component add rustfmt clippy rust-analyzer

RUN addgroup -g 1000 developer && \
    adduser -D -s /bin/bash -u 1000 -G developer developer

USER developer

EXPOSE 8000 3000

CMD ["/bin/bash"]
DOCKERFILE_EOF
            ;;
            
        *)
            echo "❌ Unsupported language: $language"
            return 1
            ;;
    esac
    
    # Create docker-compose.yml
    cat > docker-compose.yml << COMPOSE_EOF
version: '3.8'

services:
  ${template_name}:
    build: .
    container_name: ${template_name}-container
    volumes:
      - ./workspace:/workspace
      - ~/.ssh:/home/developer/.ssh:ro
      - ~/.gitconfig:/home/developer/.gitconfig:ro
    ports:
      - "3000:3000"
      - "8000:8000"
      - "8080:8080"
      - "9000:9000"
    working_dir: /workspace
    tty: true
    stdin_open: true

COMPOSE_EOF

    mkdir -p workspace
    echo "✅ Template created: $TEMPLATES_DIR/$template_name"
}

list_containers() {
    echo "📋 Available Development Containers:"
    docker ps -a --filter "label=dev-container" --format "table {{.Names}}\t{{.Status}}\t{{.Ports}}"
    echo ""
    echo "🐳 Running Containers:"
    docker ps --format "table {{.Names}}\t{{.Status}}\t{{.Ports}}"
}

start_container() {
    local container_path="$1"
    if [ -d "$container_path" ]; then
        cd "$container_path"
        echo "🚀 Starting container in: $container_path"
        docker-compose up -d
        docker-compose ps
    else
        echo "❌ Container directory not found: $container_path"
    fi
}

show_menu() {
    echo ""
    echo "Choose an action:"
    echo "1. Create Python development template"
    echo "2. Create Go development template"
    echo "3. Create Rust development template"
    echo "4. List all containers"
    echo "5. Start existing container"
    echo "6. Stop all containers"
    echo "0. Exit"
    echo ""
}

while true; do
    show_menu
    read -p "Enter your choice [0-6]: " choice
    
    case $choice in
        1)
            read -p "Enter template name: " name
            create_template "$name" "python"
            ;;
        2)
            read -p "Enter template name: " name
            create_template "$name" "go"
            ;;
        3)
            read -p "Enter template name: " name
            create_template "$name" "rust"
            ;;
        4)
            list_containers
            ;;
        5)
            read -p "Enter container directory path: " path
            start_container "$path"
            ;;
        6)
            echo "🛑 Stopping all containers..."
            docker stop $(docker ps -q) 2>/dev/null || echo "No containers to stop"
            ;;
        0)
            echo "👋 Goodbye!"
            exit 0
            ;;
        *)
            echo "❌ Invalid option. Please try again."
            ;;
    esac
    
    read -p "Press Enter to continue..."
done

echo "==============================="
EOF

# Make executable
chmod +x ~/bin/dev_container_manager.sh

echo "✅ Development container manager created!"
echo "📱 Run: ~/bin/dev_container_manager.sh"

Expected Output:

✅ Universal development container built
✅ Templates created for Python, Go, Rust
✅ Container manager script ready
🐳 Development Container Manager available

What this does: Provides comprehensive development container management! 💫

🛠️ Step 4: Advanced Development Container Features

Implement Development Container with VS Code Integration

What we’re doing: Setting up containers optimized for VS Code development.

# Create VS Code development container
mkdir -p ~/dev-containers/vscode-dev
cd ~/dev-containers/vscode-dev

# Create .devcontainer directory
mkdir -p .devcontainer

# Create devcontainer.json for VS Code integration
cat > .devcontainer/devcontainer.json << 'EOF'
{
  "name": "Alpine Development Container",
  "build": {
    "dockerfile": "Dockerfile",
    "context": ".."
  },
  
  "features": {
    "ghcr.io/devcontainers/features/common-utils:2": {
      "installZsh": true,
      "installOhMyZsh": true,
      "upgradePackages": true,
      "username": "developer",
      "uid": "1000",
      "gid": "1000"
    },
    "ghcr.io/devcontainers/features/node:1": {
      "version": "18"
    },
    "ghcr.io/devcontainers/features/python:1": {
      "version": "3.11"
    },
    "ghcr.io/devcontainers/features/go:1": {
      "version": "1.21"
    }
  },

  "customizations": {
    "vscode": {
      "extensions": [
        "ms-vscode.vscode-typescript-next",
        "ms-python.python",
        "golang.go",
        "rust-lang.rust-analyzer",
        "ms-vscode.vscode-json",
        "redhat.vscode-yaml",
        "ms-vscode.hexeditor",
        "GitLab.gitlab-workflow",
        "ms-azuretools.vscode-docker"
      ],
      "settings": {
        "terminal.integrated.defaultProfile.linux": "zsh",
        "python.defaultInterpreterPath": "/usr/local/bin/python",
        "go.gopath": "/go",
        "editor.formatOnSave": true,
        "editor.codeActionsOnSave": {
          "source.organizeImports": true
        }
      }
    }
  },

  "forwardPorts": [3000, 4200, 8000, 8080, 9000],
  
  "postCreateCommand": "echo 'Welcome to your development container!' && git --version && node --version && python --version && go version",
  
  "remoteUser": "developer",
  
  "mounts": [
    "source=${localWorkspaceFolder},target=/workspace,type=bind,consistency=cached",
    "source=${localEnv:HOME}/.ssh,target=/home/developer/.ssh,type=bind,consistency=cached,readonly",
    "source=${localEnv:HOME}/.gitconfig,target=/home/developer/.gitconfig,type=bind,consistency=cached,readonly"
  ]
}
EOF

# Create Dockerfile for VS Code development
cat > .devcontainer/Dockerfile << 'EOF'
FROM alpine:latest

# Install base packages
RUN apk add --no-cache \
    bash \
    zsh \
    git \
    curl \
    wget \
    vim \
    nano \
    openssh-client \
    build-base \
    ca-certificates \
    gnupg

# Install Node.js and npm
RUN apk add --no-cache nodejs npm

# Install Python
RUN apk add --no-cache python3 py3-pip python3-dev

# Install Go
RUN apk add --no-cache go

# Install development tools
RUN npm install -g \
    typescript \
    @types/node \
    ts-node \
    nodemon \
    eslint \
    prettier \
    @angular/cli \
    @vue/cli

RUN pip3 install \
    black \
    flake8 \
    pylint \
    mypy \
    pytest \
    jupyter \
    ipython

# Install Go tools
RUN go install golang.org/x/tools/gopls@latest
RUN go install github.com/go-delve/delve/cmd/dlv@latest

# Create developer user
RUN addgroup -g 1000 developer && \
    adduser -D -s /bin/zsh -u 1000 -G developer developer && \
    mkdir -p /home/developer/.vscode-server && \
    chown -R developer:developer /home/developer

# Install Oh My Zsh for developer user
USER developer
RUN sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" --unattended

# Set environment variables
ENV SHELL=/bin/zsh
ENV GOPATH=/go
ENV PATH=$PATH:$GOPATH/bin

WORKDIR /workspace

CMD ["/bin/zsh"]
EOF

# Create workspace directory
mkdir -p workspace

echo "✅ VS Code development container configured!"
echo "📝 To use: Open this folder in VS Code and select 'Reopen in Container'"

What this does: Creates VS Code-optimized development containers! 💫

Create Container Health Monitoring

What we’re doing: Implementing monitoring and health checks for development containers.

# Create container monitoring script
cat > ~/bin/dev_container_monitor.sh << 'EOF'
#!/bin/bash

echo "🔍 Development Container Monitor"
echo "==============================="

monitor_containers() {
    echo "📊 Container Status Overview:"
    echo ""
    
    # Get all containers
    containers=$(docker ps -a --format "{{.Names}}" | grep -E "(dev|development)")
    
    if [ -z "$containers" ]; then
        echo "❌ No development containers found"
        return 1
    fi
    
    for container in $containers; do
        echo "🐳 Container: $container"
        
        # Container status
        status=$(docker inspect --format='{{.State.Status}}' "$container" 2>/dev/null)
        echo "  Status: $status"
        
        # Resource usage
        if [ "$status" = "running" ]; then
            stats=$(docker stats --no-stream --format "table {{.CPUPerc}}\t{{.MemUsage}}\t{{.NetIO}}\t{{.BlockIO}}" "$container" 2>/dev/null | tail -n +2)
            echo "  Resources: $stats"
            
            # Health check
            health=$(docker inspect --format='{{.State.Health.Status}}' "$container" 2>/dev/null)
            if [ "$health" != "" ] && [ "$health" != "<no value>" ]; then
                echo "  Health: $health"
            fi
            
            # Uptime
            started=$(docker inspect --format='{{.State.StartedAt}}' "$container" 2>/dev/null)
            echo "  Started: $started"
        fi
        
        echo ""
    done
}

cleanup_containers() {
    echo "🧹 Cleaning up stopped development containers..."
    
    # Remove stopped development containers
    stopped_containers=$(docker ps -a --filter "status=exited" --format "{{.Names}}" | grep -E "(dev|development)")
    
    if [ ! -z "$stopped_containers" ]; then
        for container in $stopped_containers; do
            echo "  Removing: $container"
            docker rm "$container"
        done
    else
        echo "  No stopped containers to clean"
    fi
    
    # Clean up unused images
    echo "🗑️  Cleaning up unused images..."
    docker image prune -f
    
    # Clean up unused volumes
    echo "💾 Cleaning up unused volumes..."
    docker volume prune -f
    
    echo "✅ Cleanup complete!"
}

restart_container() {
    local container_name="$1"
    
    if [ -z "$container_name" ]; then
        echo "Available containers:"
        docker ps -a --format "{{.Names}}" | grep -E "(dev|development)"
        read -p "Enter container name: " container_name
    fi
    
    if docker ps -a --format "{{.Names}}" | grep -q "^${container_name}$"; then
        echo "🔄 Restarting container: $container_name"
        docker restart "$container_name"
        
        # Wait for container to start
        sleep 2
        
        # Check status
        status=$(docker inspect --format='{{.State.Status}}' "$container_name")
        echo "  Status: $status"
    else
        echo "❌ Container not found: $container_name"
    fi
}

show_logs() {
    local container_name="$1"
    local lines="${2:-50}"
    
    if [ -z "$container_name" ]; then
        echo "Available containers:"
        docker ps --format "{{.Names}}" | grep -E "(dev|development)"
        read -p "Enter container name: " container_name
    fi
    
    if docker ps --format "{{.Names}}" | grep -q "^${container_name}$"; then
        echo "📋 Last $lines log entries for: $container_name"
        echo "======================================="
        docker logs --tail "$lines" "$container_name"
    else
        echo "❌ Container not found or not running: $container_name"
    fi
}

case "${1:-menu}" in
    "monitor")
        monitor_containers
        ;;
    "cleanup")
        cleanup_containers
        ;;
    "restart")
        restart_container "$2"
        ;;
    "logs")
        show_logs "$2" "$3"
        ;;
    "menu"|*)
        echo "Available commands:"
        echo "  monitor  - Show container status and resource usage"
        echo "  cleanup  - Remove stopped containers and clean up"
        echo "  restart  - Restart a specific container"
        echo "  logs     - Show container logs"
        echo ""
        echo "Usage examples:"
        echo "  $0 monitor"
        echo "  $0 cleanup"
        echo "  $0 restart nodejs-dev-container"
        echo "  $0 logs nodejs-dev-container 100"
        ;;
esac

echo "==============================="
EOF

# Make executable
chmod +x ~/bin/dev_container_monitor.sh

# Test monitoring
~/bin/dev_container_monitor.sh monitor

echo "✅ Container monitoring system ready!"

Expected Output:

✅ VS Code development container configured
✅ Container monitoring system created
📊 Container Status Overview:
🐳 Container: nodejs-dev-container
  Status: running
  Resources: 2.34%    256.7MiB / 7.775GiB
✅ Container monitoring system ready!

What this does: Provides comprehensive container monitoring and management! 📚

🎮 Practice Time!

Let’s practice what you learned! Try these simple examples:

Example 1: Multi-Service Development Environment 🟢

What we’re doing: Creating a complete development stack with multiple services.

# Create full-stack development environment
mkdir -p ~/dev-containers/fullstack-dev
cd ~/dev-containers/fullstack-dev

# Create docker-compose for full development stack
cat > docker-compose.yml << 'EOF'
version: '3.8'

services:
  # Frontend development container
  frontend:
    build:
      context: .
      dockerfile: Dockerfile.frontend
    container_name: frontend-dev
    volumes:
      - ./frontend:/workspace
      - ~/.ssh:/home/developer/.ssh:ro
    ports:
      - "3000:3000"
      - "4200:4200"
    environment:
      - NODE_ENV=development
    networks:
      - dev-network

  # Backend development container
  backend:
    build:
      context: .
      dockerfile: Dockerfile.backend
    container_name: backend-dev
    volumes:
      - ./backend:/workspace
      - ~/.ssh:/home/developer/.ssh:ro
    ports:
      - "8000:8000"
      - "5000:5000"
    environment:
      - FLASK_ENV=development
      - DJANGO_DEBUG=True
    depends_on:
      - database
    networks:
      - dev-network

  # Database container
  database:
    image: postgres:13-alpine
    container_name: dev-database
    environment:
      - POSTGRES_DB=devdb
      - POSTGRES_USER=developer
      - POSTGRES_PASSWORD=devpass
    ports:
      - "5432:5432"
    volumes:
      - postgres_data:/var/lib/postgresql/data
      - ./database/init:/docker-entrypoint-initdb.d
    networks:
      - dev-network

  # Redis cache
  cache:
    image: redis:7-alpine
    container_name: dev-cache
    ports:
      - "6379:6379"
    networks:
      - dev-network

volumes:
  postgres_data:

networks:
  dev-network:
    driver: bridge
EOF

# Create frontend Dockerfile
cat > Dockerfile.frontend << 'EOF'
FROM node:18-alpine

WORKDIR /workspace

RUN apk add --no-cache git bash vim curl wget

RUN npm install -g \
    @angular/cli \
    @vue/cli \
    create-react-app \
    typescript \
    eslint \
    prettier

RUN addgroup -g 1000 developer && \
    adduser -D -s /bin/bash -u 1000 -G developer developer

USER developer

EXPOSE 3000 4200

CMD ["/bin/bash"]
EOF

# Create backend Dockerfile
cat > Dockerfile.backend << 'EOF'
FROM python:3.11-alpine

WORKDIR /workspace

RUN apk add --no-cache \
    git \
    bash \
    vim \
    curl \
    wget \
    build-base \
    postgresql-dev

RUN pip install \
    django \
    flask \
    fastapi \
    sqlalchemy \
    psycopg2-binary \
    redis \
    celery \
    pytest \
    black \
    flake8

RUN addgroup -g 1000 developer && \
    adduser -D -s /bin/bash -u 1000 -G developer developer

USER developer

EXPOSE 8000 5000

CMD ["/bin/bash"]
EOF

# Create workspace directories
mkdir -p frontend backend database/init

# Create sample database initialization
cat > database/init/01-init.sql << 'EOF'
-- Create sample tables for development
CREATE TABLE IF NOT EXISTS users (
    id SERIAL PRIMARY KEY,
    username VARCHAR(50) UNIQUE NOT NULL,
    email VARCHAR(100) UNIQUE NOT NULL,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

CREATE TABLE IF NOT EXISTS projects (
    id SERIAL PRIMARY KEY,
    name VARCHAR(100) NOT NULL,
    description TEXT,
    user_id INTEGER REFERENCES users(id),
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

-- Insert sample data
INSERT INTO users (username, email) VALUES 
    ('developer', '[email protected]'),
    ('tester', '[email protected]');

INSERT INTO projects (name, description, user_id) VALUES 
    ('Sample Project', 'A sample development project', 1),
    ('Test Project', 'A project for testing', 1);
EOF

echo "🚀 Starting full-stack development environment..."
docker-compose up -d

echo "✅ Full-stack development environment ready!"
echo "📱 Frontend: http://localhost:3000"
echo "🔧 Backend: http://localhost:8000"
echo "🗄️  Database: localhost:5432"

What this does: Creates a complete development infrastructure! 🌟

Example 2: Container Development Workflow Automation 🟡

What we’re doing: Building automated workflows for container-based development.

# Create development workflow automation
cat > ~/bin/dev_workflow.sh << 'EOF'
#!/bin/bash

echo "🔄 Development Workflow Automation"
echo "=================================="

PROJECT_ROOT="${1:-$(pwd)}"
CONTAINER_NAME="${2:-dev-container}"

if [ ! -d "$PROJECT_ROOT" ]; then
    echo "❌ Project directory not found: $PROJECT_ROOT"
    exit 1
fi

cd "$PROJECT_ROOT"

# Function to detect project type
detect_project_type() {
    if [ -f "package.json" ]; then
        if grep -q "react" package.json; then
            echo "react"
        elif grep -q "@angular" package.json; then
            echo "angular"
        elif grep -q "vue" package.json; then
            echo "vue"
        else
            echo "nodejs"
        fi
    elif [ -f "requirements.txt" ] || [ -f "setup.py" ]; then
        echo "python"
    elif [ -f "go.mod" ]; then
        echo "go"
    elif [ -f "Cargo.toml" ]; then
        echo "rust"
    elif [ -f "pom.xml" ] || [ -f "build.gradle" ]; then
        echo "java"
    else
        echo "unknown"
    fi
}

# Function to start development environment
start_dev_environment() {
    local project_type="$1"
    
    echo "🚀 Starting $project_type development environment..."
    
    case "$project_type" in
        "react"|"angular"|"vue"|"nodejs")
            docker run -d \
                --name "$CONTAINER_NAME" \
                -v "$PROJECT_ROOT:/workspace" \
                -v ~/.ssh:/home/developer/.ssh:ro \
                -p 3000:3000 \
                -p 4200:4200 \
                -w /workspace \
                node:18-alpine \
                tail -f /dev/null
            ;;
        "python")
            docker run -d \
                --name "$CONTAINER_NAME" \
                -v "$PROJECT_ROOT:/workspace" \
                -v ~/.ssh:/home/developer/.ssh:ro \
                -p 8000:8000 \
                -p 5000:5000 \
                -w /workspace \
                python:3.11-alpine \
                tail -f /dev/null
            ;;
        "go")
            docker run -d \
                --name "$CONTAINER_NAME" \
                -v "$PROJECT_ROOT:/workspace" \
                -v ~/.ssh:/home/developer/.ssh:ro \
                -p 8080:8080 \
                -w /workspace \
                golang:1.21-alpine \
                tail -f /dev/null
            ;;
        *)
            echo "❌ Unsupported project type: $project_type"
            return 1
            ;;
    esac
    
    # Wait for container to start
    sleep 2
    
    # Install project dependencies
    install_dependencies "$project_type"
    
    echo "✅ Development environment ready!"
}

# Function to install dependencies
install_dependencies() {
    local project_type="$1"
    
    echo "📦 Installing dependencies for $project_type project..."
    
    case "$project_type" in
        "react"|"angular"|"vue"|"nodejs")
            docker exec "$CONTAINER_NAME" sh -c "
                apk add --no-cache git bash vim curl wget build-base
                if [ -f package.json ]; then
                    npm install
                fi
            "
            ;;
        "python")
            docker exec "$CONTAINER_NAME" sh -c "
                apk add --no-cache git bash vim curl wget build-base
                pip install --upgrade pip
                if [ -f requirements.txt ]; then
                    pip install -r requirements.txt
                fi
            "
            ;;
        "go")
            docker exec "$CONTAINER_NAME" sh -c "
                apk add --no-cache git bash vim curl wget build-base
                if [ -f go.mod ]; then
                    go mod download
                fi
            "
            ;;
    esac
}

# Function to run development server
start_dev_server() {
    local project_type="$1"
    
    echo "🖥️  Starting development server..."
    
    case "$project_type" in
        "react")
            docker exec -it "$CONTAINER_NAME" npm start
            ;;
        "angular")
            docker exec -it "$CONTAINER_NAME" ng serve --host 0.0.0.0
            ;;
        "vue")
            docker exec -it "$CONTAINER_NAME" npm run serve
            ;;
        "nodejs")
            docker exec -it "$CONTAINER_NAME" npm start
            ;;
        "python")
            if [ -f "manage.py" ]; then
                docker exec -it "$CONTAINER_NAME" python manage.py runserver 0.0.0.0:8000
            elif [ -f "app.py" ]; then
                docker exec -it "$CONTAINER_NAME" python app.py
            else
                docker exec -it "$CONTAINER_NAME" python -m http.server 8000
            fi
            ;;
        "go")
            docker exec -it "$CONTAINER_NAME" go run .
            ;;
    esac
}

# Function to run tests
run_tests() {
    local project_type="$1"
    
    echo "🧪 Running tests..."
    
    case "$project_type" in
        "react"|"angular"|"vue"|"nodejs")
            docker exec "$CONTAINER_NAME" npm test
            ;;
        "python")
            docker exec "$CONTAINER_NAME" sh -c "
                if [ -f manage.py ]; then
                    python manage.py test
                else
                    pytest
                fi
            "
            ;;
        "go")
            docker exec "$CONTAINER_NAME" go test ./...
            ;;
    esac
}

# Function to build project
build_project() {
    local project_type="$1"
    
    echo "🏗️  Building project..."
    
    case "$project_type" in
        "react"|"angular"|"vue")
            docker exec "$CONTAINER_NAME" npm run build
            ;;
        "nodejs")
            docker exec "$CONTAINER_NAME" npm run build 2>/dev/null || echo "No build script found"
            ;;
        "go")
            docker exec "$CONTAINER_NAME" go build -o app .
            ;;
        "python")
            echo "Python projects typically don't require building"
            ;;
    esac
}

# Function to cleanup
cleanup() {
    echo "🧹 Cleaning up development environment..."
    docker stop "$CONTAINER_NAME" 2>/dev/null
    docker rm "$CONTAINER_NAME" 2>/dev/null
    echo "✅ Cleanup complete!"
}

# Main workflow
PROJECT_TYPE=$(detect_project_type)
echo "📋 Detected project type: $PROJECT_TYPE"
echo "📁 Project root: $PROJECT_ROOT"
echo "🐳 Container name: $CONTAINER_NAME"
echo ""

case "${3:-start}" in
    "start")
        start_dev_environment "$PROJECT_TYPE"
        ;;
    "server")
        start_dev_server "$PROJECT_TYPE"
        ;;
    "test")
        run_tests "$PROJECT_TYPE"
        ;;
    "build")
        build_project "$PROJECT_TYPE"
        ;;
    "cleanup")
        cleanup
        ;;
    *)
        echo "Usage: $0 [project_root] [container_name] [command]"
        echo "Commands: start, server, test, build, cleanup"
        ;;
esac

echo "=================================="
EOF

# Make executable
chmod +x ~/bin/dev_workflow.sh

# Test workflow
cd ~/dev-containers/nodejs-dev/workspace
~/bin/dev_workflow.sh $(pwd) test-workflow start

echo "✅ Development workflow automation ready!"

What this does: Provides comprehensive development workflow automation! 📚

🚨 Fix Common Problems

Problem 1: Container cannot access host filesystem ❌

What happened: Volume mounts are not working properly. How to fix it: Check volume mounting and permissions!

# Check current container mounts
docker inspect container-name | grep -A 10 "Mounts"

# Fix volume mounting
docker run -v "$(pwd):/workspace" -w /workspace container-image

# Fix permissions issues
docker exec container-name chown -R developer:developer /workspace

Problem 2: Container networking issues ❌

What happened: Services cannot communicate between containers. How to fix it: Configure Docker networking properly!

# Create custom network
docker network create dev-network

# Connect containers to network
docker network connect dev-network container1
docker network connect dev-network container2

# Test connectivity
docker exec container1 ping container2

Problem 3: Container resource constraints ❌

What happened: Container is running slowly or out of memory. How to fix it: Monitor and adjust resource limits!

# Check container resource usage
docker stats container-name

# Set resource limits
docker run --memory="2g" --cpus="1.5" container-image

# Monitor system resources
~/bin/dev_container_monitor.sh monitor

Don’t worry! Container development has a learning curve. You’re doing great! 💪

💡 Simple Tips

  1. Use volume mounts 📅 - Keep your code on the host system
  2. Create base images 🌱 - Build reusable development environments
  3. Network containers 🤝 - Connect services with Docker networks
  4. Monitor resources 💪 - Keep an eye on CPU and memory usage

✅ Check Everything Works

Let’s make sure your development container setup is working:

# Check Docker installation
docker --version
docker-compose --version

# List development containers
docker ps -a | grep dev

# Test container functionality
cd ~/dev-containers/nodejs-dev
docker-compose ps

# Run development workflow
~/bin/dev_workflow.sh ~/dev-containers/nodejs-dev/workspace

# Monitor containers
~/bin/dev_container_monitor.sh monitor

# Test VS Code integration
ls -la ~/dev-containers/vscode-dev/.devcontainer/

echo "Development containers fully operational! ✅"

Good output:

✅ Docker version 24.0.5, build ced0996
✅ Docker Compose version v2.20.2
✅ nodejs-dev-container   Up   0.0.0.0:3000->3000/tcp
✅ Development workflow ready
✅ Container monitoring active
✅ VS Code integration configured
Development containers fully operational! ✅

🏆 What You Learned

Great job! Now you can:

  • ✅ Install and configure Docker for development containers
  • ✅ Create language-specific development environments
  • ✅ Build universal development containers with multiple tools
  • ✅ Set up VS Code integration with development containers
  • ✅ Implement container monitoring and health checks
  • ✅ Create automated development workflows
  • ✅ Build multi-service development environments
  • ✅ Fix common container development issues

🎯 What’s Next?

Now you can try:

  • 📚 Implementing CI/CD pipelines with containerized development
  • 🛠️ Creating custom base images for your team’s development stack
  • 🤝 Setting up distributed development environments across multiple machines
  • 🌟 Building development container registries and sharing workflows

Remember: Every expert was once a beginner. You’re doing amazing! 🎉

Keep practicing and you’ll become a development container expert too! 💫