Practical Docker Deployment, Container Management, and Service Orchestration

Registry Mirror Configuration

When pulling images from public registries experiences latency, configuring local or regional mirrors in the Docker daemon configuration significantly accelerates transfer speeds. The primary configuration file resides at /etc/docker/daemon.json.

{
  "registry-mirrors": [
    "https://mirror.region-east.cloud",
    "https://docker-proxy.university.edu",
    "https://registry-mirror.example.io",
    "https://hub-mirror.cdn-provider.com"
  ]
}

To authenticate against a private or acceleraetd registry, execute the login command with your assigned credentials:

docker login mirror.region-east.cloud -u tech_admin_01 -p xK9@vL2$mN7pQ8wR

Ubuntu 24.04 Docker Installation Workflow

Following the deprecation of certain enterprise Linux distributions, Ubuntu 24.04 has become a preferred baseline for container workloads. The following script configures the official repository, installs the engine, applies mirror settings, and enables compose support.

#!/bin/bash
set -e

# Update package index and upgrade existing packages
sudo apt update -y
sudo apt upgrade -y

# Install prerequisite packages for HTTPS repositories
sudo apt install -y apt-transport-https ca-certificates curl gnupg lsb-release

# Add Docker official GPG key (modern approach)
sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
sudo chmod a+r /etc/apt/keyrings/docker.gpg

# Set up the stable repository
echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
  $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
  sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

sudo apt update -y

# Install Docker Engine, CLI, and Containerd
sudo apt install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

# Apply registry mirror configuration
sudo mkdir -p /etc/docker
cat > /tmp/daemon-config.json <<eof and="" compose="" daemon-reload="" docker="" eof="" installation="" mv="" reload="" restart="" service="" sudo="" systemctl="" systemd="" the="" verify="" version=""></eof>

Essential Container & Image Operations

Below are fundamental commands for managing runtime containers, images, networks, and storage volumes. Long-form flags are used for improved readability and scripting reliability.

# Stream live logs from a running container
docker logs --follow --timestamps my-service-container

# Display low-level metadata and configuration
docker inspect my-service-container

# Export an image to a tar archive for offline transfer
docker save --output web-app-v2.tar ghcr.io/example/web-app:v2.1.0

# Import a tar archive back into the local image store
docker load --input web-app-v2.tar

# Build a new image from a Dockerfile in the current directory
docker build --tag custom-runtime:latest .

# Create an isolated bridge network for inter-container communication
docker network create --driver bridge app-isolation-net

# Force remove all containers (running or stopped)
docker rm --force $(docker ps --all --quiet)

# Delete all local images
docker rmi --force $(docker images --quiet)

# Reclaim disk space by removing unused images, containers, and caches
docker system prune --all --volumes

Deploying Common Backend Services

MySQL Database

MySQL can be deployed with persistent storage and character set configurations. Volume mounts ensure data survives container recreation.

# MySQL 5.7 Deployment
docker run --detach --name db-legacy \
  --restart unless-stopped \
  --publish 3307:3306 \
  --volume /srv/docker-volumes/mysql57/data:/var/lib/mysql \
  --volume /srv/docker-volumes/mysql57/config:/etc/mysql/conf.d \
  --env MYSQL_ROOT_PASSWORD="LegacyRoot#2024" \
  --env TZ="Asia/Shanghai" \
  mysql:5.7.40 \
  --character-set-server=utf8mb4 \
  --collation-server=utf8mb4_unicode_ci

# MySQL 8.0 Deployment
docker run --detach --name db-modern \
  --restart unless-stopped \
  --publish 3308:3306 \
  --volume /srv/docker-volumes/mysql8/data:/var/lib/mysql \
  --volume /srv/docker-volumes/mysql8/config:/etc/mysql/conf.d \
  --env MYSQL_ROOT_PASSWORD="ModernRoot#2024" \
  --env TZ="Asia/Shanghai" \
  mysql:8.0.35 \
  --character-set-server=utf8mb4 \
  --collation-server=utf8mb4_unicode_ci \
  --lower_case_table_names=1

# Enable remote root access (execute inside container)
docker exec -it db-modern mysql -u root -pModernRoot#2024 -e \
  "ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'ModernRoot#2024'; FLUSH PRIVILEGES;"

Redis Cache

docker run --detach --name cache-store \
  --restart unless-stopped \
  --publish 6380:6379 \
  --volume /srv/docker-volumes/redis/data:/data \
  redis:7.2.3 \
  --requirepass "CacheAuth!2024" \
  --appendonly yes

Elasticsearch & Kibana

Deploying the search and visualization stack requires memory allocation adjustments and network exposure for API and UI access.

docker run --detach --name search-engine \
  --user 1000 \
  --restart unless-stopped \
  --publish 9201:9200 \
  --publish 9301:9300 \
  --volume /srv/docker-volumes/es/data:/usr/share/elasticsearch/data \
  --env "discovery.type=single-node" \
  --env "ES_JAVA_OPTS=-Xms512m -Xmx512m" \
  elasticsearch:8.11.1

docker run --detach --name data-viz \
  --restart unless-stopped \
  --publish 5602:5601 \
  --env "ELASTICSEARCH_HOSTS=http://search-engine:9200" \
  kibana:8.11.1

RabbitMQ with Delayed Message Exchange

The management interface and delayed exchange plugin provide advanced message routing capabilities.

# Pull and run the management image
docker run --detach --name msg-broker \
  --restart unless-stopped \
  --publish 5673:5672 \
  --publish 15673:15672 \
  --volume /srv/docker-volumes/rabbitmq/data:/var/lib/rabbitmq \
  rabbitmq:3.12-management

# Inject the delayed exchange plugin
docker cp rabbitmq_delayed_message_exchange-3.12.0.ez msg-broker:/plugins/

# Activate the plugin inside the running container
docker exec -it msg-broker rabbitmq-plugins enable rabbitmq_delayed_message_exchange

# Apply changes
docker restart msg-broker

XXL-Job Distributed Scheduler

docker run --detach --name task-scheduler \
  --restart unless-stopped \
  --publish 8081:8080 \
  --volume /srv/docker-volumes/xxljob/logs:/data/applogs \
  --env PARAMS="--spring.datasource.url=jdbc:mysql://192.168.1.50:3308/xxl_job_db?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai \
    --spring.datasource.username=root \
    --spring.datasource.password=ModernRoot#2024" \
  xuxueli/xxl-job-admin:2.4.0

MinIO Object Storage

docker run --detach --name object-store \
  --restart unless-stopped \
  --publish 9001:9000 \
  --publish 9900:9900 \
  --volume /srv/docker-volumes/minio/data:/data \
  --env MINIO_ROOT_USER="storage-admin" \
  --env MINIO_ROOT_PASSWORD="SecureStore#2024" \
  minio/minio:latest server /data --console-address ":9900"

Nginx Web Server

docker run --detach --name web-gateway \
  --restart unless-stopped \
  --publish 8090:80 \
  --volume /srv/docker-volumes/nginx/conf.d:/etc/nginx/conf.d \
  --volume /srv/docker-volumes/nginx/nginx.conf:/etc/nginx/nginx.conf:ro \
  --volume /srv/docker-volumes/nginx/www:/usr/share/nginx/html \
  nginx:1.25.3

Building a Custom Python Data Science Environment

Containerizing Python applications ensures reproducible environments. The following Dockerfile utilizes a slim base image, installs pinned dependencies, and cleans up build artifacts to minimize final image size.

# requirements.txt
numpy==1.26.4
pandas==2.2.1
scipy==1.12.0
matplotlib==3.8.4
openpyxl==3.1.2
netCDF4==1.6.5
xarray==2024.2.0
dask==2024.2.1

# Dockerfile
FROM python:3.12-slim

WORKDIR /app-runtime

# Copy dependency manifest first to leverage Docker cache
COPY requirements.txt .

# Install dependencies without caching, then remove pyc files and pip cache
RUN pip install --no-cache-dir -r requirements.txt && \
    find /usr/local/lib -type f -name "*.pyc" -delete && \
    rm -rf /root/.cache /tmp/*

# Copy application source code (exclude heavy files via .dockerignore)
COPY ./src /app-runtime/src

# Default execution command
CMD ["python", "/app-runtime/src/main_pipeline.py"]

Build the image using:

docker build --tag py-data-engine:v1.0 .

Running MATLAB in Containerized Mode

MathWorks provides official container images that support both headless shell execution and browser-based desktop environments. Shared memory allocation must be increased to prevent runtime crashes during visualization tasks.

# Browser-based desktop interface
docker run --detach --name matlab-web \
  --restart unless-stopped \
  --publish 8890:8888 \
  --shm-size=1G \
  ghcr.io/mathworks/matlab:r2023b -browser

# Command-line shell interface
docker run --detach --name matlab-cli \
  --restart unless-stopped \
  --shm-size=1G \
  ghcr.io/mathworks/matlab:r2023b -shell

Tags: docker containerization Ubuntu MySQL Redis

Posted on Mon, 21 Sep 2026 16:11:12 +0000 by cuteflower