Skip to main content

Docker Containers

Containers are the fundamental building blocks of Docker applications. In WhaleTUI, you can manage containers efficiently through an intuitive interface that simplifies common operations.

What are Containers?

Docker containers are lightweight, standalone, and executable packages that include everything needed to run an application: code, runtime, system tools, system libraries, and settings.

Container Lifecycle in WhaleTUI

1. Viewing Containers

The Containers tab in WhaleTUI displays all containers on your system:

  • Running Containers: Currently active containers
  • Stopped Containers: Containers that have been stopped
  • Container Status: Health, uptime, and resource usage

2. Container Information

Each container displays key information:

  • Name: Human-readable container identifier
  • Image: Base image used to create the container
  • Status: Current state (running, stopped, paused)
  • Ports: Exposed ports and mappings
  • Size: Disk space used by the container

Basic Container Operations

Starting a Container

# Using WhaleTUI UI
1. Press ':' then type 'containers' to navigate to Containers view
2. Select a stopped container using arrow keys
3. Press 's' to start the container
4. Container will begin running

# Using Docker CLI (alternative)
docker start <container_id>

Stopping a Container

# Using WhaleTUI UI
1. Select a running container using arrow keys
2. Press 'S' to stop the container
3. Container will stop gracefully

# Using Docker CLI (alternative)
docker stop <container_id>

Restarting a Container

# Using WhaleTUI UI
1. Select a container (running or stopped) using arrow keys
2. Press 'r' to restart the container
3. Container will restart with the same configuration

# Using Docker CLI (alternative)
docker restart <container_id>

Removing a Container

# Using WhaleTUI UI

1. Select a stopped container using arrow keys
2. Press 'd' to delete the container
3. Confirm the action with 'Enter'
4. Container will be permanently removed

# Using Docker CLI (alternative)
docker rm <container_id>

Advanced Container Operations

Viewing Container Logs

# Using WhaleTUI UI
1. Select a container using arrow keys
2. Press 'l' to open logs view
3. Navigate through log entries using arrow keys
4. Press 'ESC' to return to main view

# Using Docker CLI (alternative)
docker logs <container_id>

Inspecting Containers

# Using WhaleTUI UI
1. Select a container using arrow keys
2. Press 'i' to inspect the container
3. View detailed information in JSON format
4. Press 'ESC' to return to main view

# Using Docker CLI (alternative)
docker inspect <container_id>

Container Configuration

Environment Variables

Containers can be configured with environment variables:

# Set environment variables when running
docker run -e VAR_NAME=value -e ANOTHER_VAR=value image_name

# Environment variables can be configured when creating containers

Port Mappings

Expose container ports to the host:

# Map host port 8080 to container port 80
docker run -p 8080:80 nginx

# Port mappings can be configured when creating containers

Volume Mounts

Persist data between container runs:

# Mount host directory to container
docker run -v /host/path:/container/path image_name

# Volume mounts can be configured when creating containers

Container Resource Management

Resource Limits

Set limits on container resource usage:

# Limit memory and CPU
docker run --memory=512m --cpus=1.0 image_name

# Resource limits can be configured when creating containers

Resource Monitoring

WhaleTUI provides real-time resource monitoring:

  • CPU Usage: Current CPU consumption
  • Memory Usage: RAM usage and limits
  • Network I/O: Network traffic statistics
  • Disk I/O: Storage access patterns

Best Practices

Container Naming

Use descriptive names for containers:

# Good naming examples
web-server-prod
database-staging
api-gateway-dev

# Avoid generic names
container1
test
temp

Resource Cleanup

Regularly clean up unused containers:

# Remove stopped containers
docker container prune

# Use Docker CLI to clean up stopped containers

Health Checks

Implement health checks for production containers:

# Add health check to Dockerfile
HEALTHCHECK --interval=30s --timeout=3s \
CMD curl -f http://localhost/ || exit 1

Troubleshooting

Common Issues

Container Won't Start

# Check container logs
docker logs <container_id>

# Verify image exists
docker images

# Check resource availability
docker system df

Container Performance Issues

# Monitor resource usage
docker stats <container_id>

# Check for resource limits
docker inspect <container_id> | grep -i memory

Network Connectivity

# Test container networking
docker exec <container_id> ping google.com

# Check port bindings
docker port <container_id>

Next Steps

Swarm Mode

When running in swarm mode, containers are distributed across multiple nodes:

# Deploy service across multiple nodes
docker service create --name web --replicas 3 nginx:latest

# Scale service across available nodes
docker service scale web=5

# Check service distribution across nodes
docker service ps web

Key Concepts:

  • Node Distribution: Containers are automatically distributed across available nodes
  • Load Balancing: Swarm provides built-in load balancing for services
  • High Availability: Services continue running even if individual nodes fail
  • Resource Management: Swarm considers node resources when scheduling containers