← Back to Documentation

How to Deploy and Monitor MySQL Docker Containers

This guide walks through deploying MySQL containers using ServerBuddy's visual interface, covering both basic deployments and production configurations.

Prerequisites

Your Linux server needs:

  • Docker or Podman installed
  • 512GB+ available RAM
  • 10GB+ free disk space

You can check Docker installation by navigating to the "Containers" tab or by running the following in the Terminal:

docker --version
# or
podman --version

Creating a MySQL Container with GUI

Step 1: Navigate to Docker Management

  1. Connect to your server via ServerBuddy
  2. Click the "Containers" tab

Docker Containers View

Step 2: Configure Container Parameters

Click the "+ Add" button in the top right to open the container dialog:

Basic Configuration

  • Image: mysql:8.0 (or mysql:latest for newest version)
  • Container Name: production-mysql (descriptive naming)
  • Command: Leave empty (uses MySQL default entrypoint)

Port Mappings

Enter the following in the port mappings section:

  • Host Port: 3306Container Port: 3306
  • Alternative: Use 3307 on host if 3306 is occupied

Environment Variables (Critical for MySQL)

Add these essential MySQL environment variables:

Variable Value
MYSQL_ROOT_PASSWORD YourSecurePassword123!
MYSQL_DATABASE application_dbf
MYSQL_USER app_user
MYSQL_PASSWORD AppUserPassword346!

Volume Mappings for Data Persistence

Configure persistent storage to survive container restarts:

  • Mount: mysql-production-db (Docker volume name)
  • Container Path: /var/lib/mysql

This ensures your database persists even if the container is removed.

Network Configuration

  • Choose custom network for multi-container applications
  • ServerBuddy shows available networks in a dropdown

Runtime Options

  • Restart Policy: Select "Unless Stopped" for production
  • Run in detached mode: Keeps container running in background
  • Remove on exit: Keep unchecked for databases

New MySQL Container Configuration

Step 3: Deploy the Container

Click "Create Container" to:

  1. Pull the MySQL image if not present
  2. Create volume directories
  3. Start the container with specified configuration
  4. Display creation status

The container should be running within 15-20 seconds.

Monitoring MySQL Container Health

Container Status Indicators

The Docker containers view displays:

Container Status Indicators

  • 🟢 Green: Running healthy
  • 🟡 Yellow: Starting/restarting
  • 🔴 Red: Stopped or errored
  • Gray: Paused

Available Container Actions

Hover over the container row to access:

  • Start/Stop/Restart controls

Checking MySQL Performance

Container Resource Usage

You can view this by double clicking on your container entry in the containers table.

MySQL Container Resource Monitoring

The container details view shows:

  • Memory consumption vs. limits
  • CPU usage percentage (real-time graph)
  • Network I/O rates (inbound/outbound)
  • Disk read/write operations

MySQL Internal Metrics

Connect via the Terminal tab:

  1. Click the Terminal tab
  2. Connect to MySQL container

Connect to MySQL:

docker exec -it production-mysql mysql -u root -p

Run performance queries:

SHOW STATUS LIKE 'Threads_connected';
SHOW PROCESSLIST;
SHOW GLOBAL STATUS LIKE 'Slow_queries';

Log Analysis

You can view the logs for the container in the "Logs" tab by changing the log source to "Containers", and then selecting your container from the dropdown list.

The log viewer offers:

  • Filtering by log level (ERROR, WARNING)
  • Text search across logs
  • Real-time updates

Troubleshooting Connection Issues

If you can't connect to MySQL: 1. Check port mapping in container details (default: 3306) 2. Review container logs for authentication errors 3. Verify MySQL user has remote access permissions (% host) 4. Confirm firewall rules allow the connection

Security Best Practices

  • Use strong passwords for MySQL users
  • Limit port exposure to specific IPs when possible
  • Set resource limits to prevent resource exhaustion
  • Implement regular backup strategy

Common Issues and Solutions

Container Won't Start

  • Check logs for error messages
  • Verify port availability
  • Ensure image exists
  • Check volume mount permissions

Connection Refused

  • Confirm container is running
  • Verify port mapping
  • Check firewall rules
  • Review MySQL user permissions

Key Takeaways

  • Always use volumes for data persistence at /var/lib/mysql
  • Set specific image tags (e.g., mysql:8.0) instead of 'latest'
  • Configure resource limits to prevent container from consuming all system resources
  • Use restart policies for automatic recovery