Lost Your `docker run` Command? Don't Panic! Rebuild It Perfectly with `docker inspect`
Content
## The Scenario
In our daily development and operations work, we often encounter a situation where a critical Docker container is running smoothly in production, but over time, the `docker run` command or `docker-compose.yml` file used to create it has been lost. When it comes time to migrate the service, perform disaster recovery, or replicate the environment for testing, we face the challenge of accurately recreating the container's configuration. Fortunately, Docker provides a powerful introspection tool: `docker inspect`. It allows us to act like detectives and unearth all the configuration details from a running container.
This article, by DP@lib00, will guide you through a practical example with a MinIO container, showing you how to reconstruct the original `docker run` command step-by-step from the `docker inspect` output. We'll also cover how to verify the container's timezone settings.
---
## Step 1: Get the Container's Detailed Information
First, we need to use the `docker inspect` command with the target container's name or ID. This will return a JSON object containing all of the container's configuration information.
```bash
docker inspect minio_lib00
```
You will get a large JSON output. Don't worry; we only need to focus on the key parts.
---
## Step 2: Parse the JSON Output and Rebuild the Command
We will analyze the key fields from the `docker inspect` output one by one and map them back to the corresponding parameters of the `docker run` command.
### 1. Container Name (`--name`)
Look for the `Name` field in the JSON. It usually starts with a `/`.
```json
{
"Name": "/minio_lib00"
}
```
This corresponds to the `--name` argument in `docker run`.
> **Reconstructed Part**: `--name minio_lib00`
### 2. Detached Mode (`-d`)
Check the `Status` in the `State` object and `AttachStdin` and `Tty` in the `Config`. If the container is running (`"Status": "running"`) and is not in an interactive mode (`"AttachStdin": false`, `"Tty": false`), it was likely started in detached mode.
> **Reconstructed Part**: `-d`
### 3. Port Mappings (`-p`)
The `HostConfig.PortBindings` object details the port mapping relationship between the host and the container.
```json
"PortBindings": {
"9000/tcp": [
{
"HostIp": "",
"HostPort": "39000"
}
],
"9001/tcp": [
{
"HostIp": "",
"HostPort": "39001"
}
]
}
```
Here, the host's port `39000` is mapped to the container's port `9000`, and `39001` is mapped to `9001`.
> **Reconstructed Part**: `-p 39000:9000 -p 39001:9001`
### 4. Volume Mounts (`-v`)
The `HostConfig.Binds` array contains information about all bind mounts.
```json
"Binds": [
"/data/wiki.lib00.com/minio/data:/data"
]
```
This indicates that the host directory `/data/wiki.lib00.com/minio/data` is mounted to the container's `/data` directory.
> **Reconstructed Part**: `-v /data/wiki.lib00.com/minio/data:/data`
### 5. Environment Variables (`-e`)
The `Config.Env` array lists all environment variables injected into the container. We are usually only interested in the custom variables set by the user at launch.
```json
"Env": [
"TZ=Asia/Shanghai",
"MINIO_ROOT_USER=admin_dp",
"MINIO_ROOT_PASSWORD=admin_dp_password",
"MINIO_SERVER_URL=https://s3.lib00.com",
"MINIO_BROWSER_REDIRECT_URL=https://s3.lib00.com",
...
]
```
> **Reconstructed Part**:
> ```shell
> -e "TZ=Asia/Shanghai" \
> -e "MINIO_ROOT_USER=admin_dp" \
> -e "MINIO_ROOT_PASSWORD=admin_dp_password" \
> -e "MINIO_SERVER_URL=https://s3.lib00.com" \
> -e "MINIO_BROWSER_REDIRECT_URL=https://s3.lib00.com"
> ```
### 6. Network Configuration (`--network`)
The `HostConfig.NetworkMode` field specifies the Docker network the container is connected to.
```json
"NetworkMode": "lib00_net"
```
> **Reconstructed Part**: `--network lib00_net`
### 7. Image Name and Startup Command
The `Config.Image` field is the image used by the container, while `Config.Cmd` or `Args` is the command executed when the container starts.
```json
{
"Image": "minio/minio:RELEASE.2025-04-22T22-12-26Z",
"Cmd": [
"server",
"/data",
"--console-address",
":9001"
]
}
```
> **Reconstructed Part**: `minio/minio:RELEASE.2025-04-22T22-12-26Z server /data --console-address :9001`
---
## The Final Reconstructed Command
By combining all the parts above, we get the complete `docker run` command:
```bash
docker run -d \
--name minio_lib00 \
-p 39000:9000 \
-p 39001:9001 \
-v /data/wiki.lib00.com/minio/data:/data \
-e "TZ=Asia/Shanghai" \
-e "MINIO_ROOT_USER=admin_dp" \
-e "MINIO_ROOT_PASSWORD=admin_dp_password" \
-e "MINIO_SERVER_URL=https://s3.lib00.com" \
-e "MINIO_BROWSER_REDIRECT_URL=https://s3.lib00.com" \
--network lib00_net \
minio/minio:RELEASE.2025-04-22T22-12-26Z \
server /data --console-address :9001
```
---
## Bonus Tip: How to Verify Timezone in a Container?
In the command above, we set the timezone using `-e "TZ=Asia/Shanghai"`. How can we verify that it has taken effect? We can use `docker exec` to run commands inside the container.
### Method 1: Use the `date` command (Most Common)
This is the quickest method.
```bash
docker exec minio_lib00 date
# Expected output will include the CST (China Standard Time) identifier
# Mon Oct 28 15:30:00 CST 2024
```
### Method 2: Check the `/etc/localtime` Symlink
Check if this file correctly links to the specified timezone file.
```bash
docker exec minio_lib00 ls -l /etc/localtime
# Expected output
# lrwxrwxrwx 1 root root 32 Oct 28 10:10 /etc/localtime -> /usr/share/zoneinfo/Asia/Shanghai
```
### Method 3: Print the `TZ` Environment Variable
Confirm that the environment variable has been successfully injected.
```bash
docker exec minio_lib00 sh -c 'echo $TZ'
# Expected output
# Asia/Shanghai
```
---
## Conclusion
`docker inspect` is a powerful tool and a 'superpower' that every Docker user should master. By analyzing its output, we can not only reconstruct lost startup commands but also gain a deeper understanding of how containers work internally. We hope this guide from wiki.lib00 helps you manage your containerized applications more confidently.
Related Contents
Resolving PHP "could not find driver" Error: Ultimate Guide to Missing PDO Database Drivers
Duration: 00:00 | DP | 2026-07-04 08:03:00Resolving Nginx Permission Denied (13) Errors for WebP Images Generated by PHP Imagick
Duration: 00:00 | DP | 2026-07-05 21:17:00How to Fix Mac mini Not Receiving SMS Messages and iCloud Sync Stuck
Duration: 00:00 | DP | 2026-07-06 22:07:00Complete Guide to Installing and Configuring Git Server on Synology NAS: Basic to Advanced
Duration: 00:00 | DP | 2026-07-16 20:39:02Why Do .smbdelete Hidden Files Appear After Deleting on Mac SMB Shares? Causes & Ultimate Solutions
Duration: 00:00 | DP | 2026-06-27 19:10:00Complete Guide to Setting Docker Container Timezone to UTC+8 (Asia/Shanghai)
Duration: 00:00 | DP | 2026-06-30 20:43:30Ultimate Guide to Fixing Nginx [warn] conflicting server name Warning
Duration: 00:00 | DP | 2026-07-21 09:02:28Fixing 'Unable to locate package openjdk-17-jdk' in PHP 8 Docker (Debian Trixie)
Duration: 00:00 | DP | 2026-07-25 09:23:18Docker Compose Advanced: Configuring Static IPs and Cross-Container SOCKS5 Proxies
Duration: 00:00 | DP | 2026-07-26 09:28:30Nginx Reverse Proxy Guide: Elegantly Routing Specific Subdirectories to Docker Containers
Duration: 00:00 | DP | 2026-07-26 21:31:06DevOps Practice: How to Safely Clear Logs of a Running Docker Container?
Duration: 00:00 | DP | 2026-07-27 09:33:42Ultimate Guide to Setting Up Proxies on CentOS: Global Configuration and Troubleshooting
Duration: 00:00 | DP | 2026-07-27 21:36:19Practical Guide: Translating Complex Docker Compose to Docker Run Commands
Duration: 00:00 | DP | 2026-07-29 09:44:07The Ultimate Guide to Docker Cron Logging: Host vs. Container Redirection - Are You Doing It Right?
Duration: 00:00 | DP | 2026-01-05 08:03:52Cron Job Failing? The Ultimate Guide to Fixing 'docker: command not found'
Duration: 00:00 | DP | 2026-08-01 09:59:44The Ultimate 'Connection Refused' Guide: A PHP PDO & Docker Debugging Saga of a Forgotten Port
Duration: 00:00 | DP | 2025-12-03 09:03:20Solving the MySQL Docker "Permission Denied" Error on Synology NAS: A Step-by-Step Guide
Duration: 00:00 | DP | 2025-12-03 21:19:10How Can a Docker Container Access the Mac Host? The Ultimate Guide to Connecting to Nginx
Duration: 00:00 | DP | 2025-12-08 23:57:30Recommended
From Guzzle to Native cURL: A Masterclass in Refactoring a PHP Translator Component
00:00 | 105Learn how to replace Guzzle with native PHP cURL f...
The Ultimate Nginx Guide: How to Elegantly Redirect Multi-Domain HTTP/HTTPS Traffic to a Single Subdomain
00:00 | 122This article provides an in-depth guide on how to ...
Beyond 99.9%: A Deep Dive into a User-Centric Weighted Sampling Algorithm for Availability
00:00 | 31Traditional availability calculation (success/tota...
The Ultimate Guide to Fixing the "Expected parameter of type..." Mismatch Error in PhpStorm
00:00 | 117Encountering the "Expected parameter of type 'Chil...