Operations 14 min read

Recover Lost Docker Run Commands in 3 Steps: runlike + composerize Guide

This tutorial demonstrates how to reverse-engineer Docker run commands from running containers using runlike, convert them to Docker Compose files with composerize, and safely migrate legacy containers to version-controlled configurations, using a MySQL 8.0.35 example with volumes, environment variables, and resource limits.

Cilantro Loves Linux
Cilantro Loves Linux
Cilantro Loves Linux
Recover Lost Docker Run Commands in 3 Steps: runlike + composerize Guide

Problem Scenario: Undocumented Legacy MySQL Container

Many operations engineers inherit servers running Docker containers without documentation — unknown startup commands, missing configs, and departed colleagues. The article simulates a MySQL 8.0.35 container named prod-mysql-db deployed with a complex docker run command including:

Port mapping: -p 3306:3306 Volumes: /opt/mysql/data:/var/lib/mysql, /opt/mysql/conf:/etc/mysql/conf.d, /opt/mysql/init.sql:/docker-entrypoint-initdb.d/init.sql Environment variables: MYSQL_ROOT_PASSWORD, MYSQL_DATABASE=my_app_db, MYSQL_USER=app_user, MYSQL_PASSWORD Resource limits: --memory=2g --cpus=1.5 Restart policy: --restart=unless-stopped MySQL-specific flags:

--default-authentication-plugin=mysql_native_password --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci

Only the container name is known; the original command is lost.

Step 1: Reverse-Engineer the docker run Command with runlike

Installation Options

Option 1 (pip3):

# Install pip3 if missing
sudo yum install python3-pip
# Use Tsinghua mirror for speed
mkdir -p ~/.pip
echo -e "[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple" > ~/.pip/pip.conf
pip3 install runlike

Option 2 (Docker image):

docker pull assaflavie/runlike:1.5.4

Generate the Command

# Via pip3 installation
runlike -p prod-mysql-db

# Via Docker image
docker run -v /var/run/docker.sock:/var/run/docker.sock assaflavie/runlike:1.5.4 prod-mysql-db

The tool outputs a complete docker run command reconstructing all original parameters:

docker run --name=prod-mysql-db \
  --hostname=727209fab8cc \
  --mac-address=02:42:ac:11:00:02 \
  --volume /opt/mysql/init.sql:/docker-entrypoint-initdb.d/init.sql \
  --volume /opt/mysql/conf:/etc/mysql/conf.d \
  --volume /opt/mysql/data:/var/lib/mysql \
  --env='MYSQL_ROOT_PASSWORD=SuperSecretRootPassword123!' \
  --env=MYSQL_DATABASE=my_app_db \
  --env=MYSQL_USER=app_user \
  --env='MYSQL_PASSWORD=UserPassword456!' \
  --network=bridge \
  -p 3306:3306 \
  --expose=33060 \
  --restart=unless-stopped \
  --runtime=runc \
  --memory="2147483648" \
  --detach=true \
  mysql:8.0.35 \
  --default-authentication-plugin=mysql_native_password --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci

All critical details — ports, volumes, env vars, restart policy, memory limit (2147483648 bytes = 2 GiB), and MySQL server arguments — are recovered.

Step 2: Convert to Docker Compose with composerize

Online Conversion (Recommended)

Visit https://www.composerize.com/, paste the generated docker run command, and the tool produces a docker-compose.yml.

Command-Line Conversion

# Install
npm install -g composerize

# Convert (paste the full run command)
composerize docker run --name=prod-mysql-db \
  --hostname=727209fab8cc \
  --mac-address=02:42:ac:11:00:02 \
  --volume /opt/mysql/init.sql:/docker-entrypoint-initdb.d/init.sql \
  --volume /opt/mysql/conf:/etc/mysql/conf.d \
  --volume /opt/mysql/data:/var/lib/mysql \
  --env='MYSQL_ROOT_PASSWORD=SuperSecretRootPassword123!' \
  --env=MYSQL_DATABASE=my_app_db \
  --env=MYSQL_USER=app_user \
  --env='MYSQL_PASSWORD=UserPassword456!' \
  --network=bridge \
  -p 3306:3306 \
  --expose=33060 \
  --restart=unless-stopped \
  --runtime=runc \
  --memory="2147483648" \
  --detach=true \
  mysql:8.0.35 \
  --default-authentication-plugin=mysql_native_password --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci

Resulting docker-compose.yml

services:
  mysql:
    container_name: prod-mysql-db
    hostname: 727209fab8cc
    mac_address: 02:42:ac:11:00:02
    volumes:
      - /opt/mysql/init.sql:/docker-entrypoint-initdb.d/init.sql
      - /opt/mysql/conf:/etc/mysql/conf.d
      - /opt/mysql/data:/var/lib/mysql
    environment:
      - MYSQL_ROOT_PASSWORD=SuperSecretRootPassword123!
      - MYSQL_DATABASE=my_app_db
      - MYSQL_USER=app_user
      - MYSQL_PASSWORD=UserPassword456!
    network_mode: bridge
    ports:
      - 3306:3306
    expose:
      - "33060"
    restart: unless-stopped
    runtime: runc
    deploy:
      resources:
        limits:
          memory: "2147483648"
    image: mysql:8.0.35
    command:
      --default-authentication-plugin=mysql_native_password
      --character-set-server=utf8mb4
      --collation-server=utf8mb4_unicode_ci

Step 3: Verify and Deploy

1. Stop Old Container (with Backup)

# Backup data first
mkdir -p /data/mysql-backup
docker cp prod-mysql-db:/var/lib/mysql /data/mysql-backup

# Stop and remove old container
docker stop prod-mysql-db
docker rm prod-mysql-db

2. Start with New Compose Configuration

cd /opt/mysql/
vim docker-compose.yml  # paste the generated content
docker-compose up -d

3. Validate Service Health

# Check container status
docker-compose ps

# View logs
docker-compose logs mysql

# Test database connection
docker exec -it prod-mysql-db mysql -h 127.0.0.1 -u root -p'SuperSecretRootPassword123!' -e "SHOW DATABASES;"

The verification confirms the migrated container runs identically with the recovered configuration.

Summary and Recommendations

The runlike + composerize combo solves the "lost Docker command" problem for any container, not just MySQL. The author advises operations teams to:

Regular Audits: Periodically check all running containers for documentation coverage.

Standardize First: Require Docker Compose or higher-level orchestration for new projects.

Document Everything: Store critical container configs in version control.

Security First: Use env files for secrets and enforce strict permissions.

Prevention beats cure — establishing standardized container management processes makes operations smoother and safer.

Tool References

runlike

:

https://github.com/lavie/runlike
composerize

:

https://www.composerize.com/
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Dockeroperationsmysqlcontainer-managementdocker-composelegacy-migrationrunlikecomposerize
Cilantro Loves Linux
Written by

Cilantro Loves Linux

Focused on Linux system operations and maintenance technology exchange, regularly publishing in-depth technical articles covering core areas such as system architecture, performance optimization, and security hardening. Whether you are a beginner or a seasoned expert, you can find valuable resources to enhance your skills and solve problems here. Follow us to explore the mysteries of Linux operations!

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.