Practical Guide: Translating Complex Docker Compose to Docker Run Commands
Content
In daily DevOps and development workflows, `docker-compose` is an excellent tool for managing multi-container applications. However, in certain scenarios—such as quick debugging, writing automated shell scripts, or working in minimalist environments that lack Compose support—we need to translate the configuration from `docker-compose.yml` into a native `docker run` command.
This article (originally published on [wiki.lib00.com](https://wiki.lib00.com)) breaks down the key details of this translation process using a real-world proxy API service configuration.
## The Scenario: Analyzing the Docker Compose Config
Suppose we have the following `docker-compose.yml` file. It defines a service named `cli-proxy-API`, including image pull policies, environment variables, port mappings, volume mounts, and an external network with a static IP:
```yaml
services:
cli-proxy-API:
image: eceasy/cli-proxy-api:v7.1.50
pull_policy: always
container_name: ee-cpa
environment:
TZ: America/New_York
CPA_DATA_DIR: /data
CPA_CONFIG_PATH: /data/config.yaml
CPA_AUTH_DIR: /root/.cli-proxy-api
CPA_ALLOW_REMOTE_MANAGEMENT: "true"
CPA_MANAGEMENT_PASSWORD: ""
ports:
- "8316:8317"
volumes:
- ./data:/data
- ./auths:/root/.cli-proxy-api
restart: unless-stopped
networks:
eeLan:
ipv4_address: 172.18.0.16
networks:
eeLan:
external: true # Tells Compose this network already exists
```
---
## The Solution: Translating to Docker Run
Based on the configuration above, author **DP@lib00** has compiled the equivalent single-line `docker run` command. For better readability, `\` is used for line breaks:
```bash
docker run -d \
--name ee-cpa \
--pull always \
--restart unless-stopped \
--network eeLan \
--ip 172.18.0.16 \
-p 8316:8317 \
-e TZ=America/New_York \
-e CPA_DATA_DIR=/data \
-e CPA_CONFIG_PATH=/data/config.yaml \
-e CPA_AUTH_DIR=/root/.cli-proxy-api \
-e CPA_ALLOW_REMOTE_MANAGEMENT="true" \
-e CPA_MANAGEMENT_PASSWORD="" \
-v $(pwd)/data:/data \
-v $(pwd)/auths:/root/.cli-proxy-api \
eceasy/cli-proxy-api:v7.1.50
```
---
## Core Parameter Breakdown
During the translation process, several key points require special attention:
1. **Run in Background (`-d`)**: Compose typically runs in the background using `docker-compose up -d`. In the native command, we must explicitly add the `-d` flag.
2. **Image Pull Policy (`--pull always`)**: Corresponds to `pull_policy: always` in Compose, ensuring Docker attempts to pull the latest image version before starting the container.
3. **Network & Static IP (`--network` & `--ip`)**: The original config specifies an external network `eeLan` and a fixed IPv4 address `172.18.0.16`. In `docker run`, this is achieved by combining the `--network` and `--ip` flags.
4. **Relative Path Mounts (`-v`)**: This is the most common pitfall! Compose allows relative paths in `volumes` (like `./data`), but `docker run` requires **absolute paths** for host directories. Therefore, we cleverly use `$(pwd)/data` to dynamically get the absolute path of the current directory. This is a highly recommended practice in **lib00**'s automated deployment scripts.
5. **Environment Variables (`-e`)**: Every key-value pair under `environment` must be translated into a `-e KEY=VALUE` format.
---
## Bonus Tip: Creating the External Network
Since the Compose file declares `eeLan` as an external network (`external: true`), this network must already exist on the host before executing the `docker run` command. If it doesn't, you will encounter a startup error.
You can pre-create the network and specify its subnet using the following command:
```bash
# Create a custom network named eeLan and specify the subnet range
docker network create --subnet=172.18.0.0/16 eeLan
```
By mastering this translation logic, you will be well-equipped whether you are troubleshooting container issues or writing lightweight initialization scripts. For more containerization tips, stay tuned to wiki.lib00.com!
Related Contents
Complete 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:30Stop Using rm! 5 Pro Ways to Quickly Clear Log Files in Linux
Duration: 00:00 | DP | 2026-07-18 20:49:27Never Lose Output Again: How to Show Unlimited Scrollback History in macOS iTerm2
Duration: 00:00 | DP | 2026-07-21 21:05:04Fixing '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:42Say Goodbye to Line-by-Line Deletion: A Guide to Efficiently Bulk Editing and Cleaning Crontab on Linux
Duration: 00:00 | DP | 2026-07-30 09:49:20The Ultimate Guide to Docker Cron Logging: Host vs. Container Redirection - Are You Doing It Right?
Duration: 00:00 | DP | 2026-01-05 08:03:52The 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:10NVM/Node Command Not Found in New macOS Terminals? A Two-Step Permanent Fix!
Duration: 00:00 | DP | 2025-12-04 09:35:00How Can a Docker Container Access the Mac Host? The Ultimate Guide to Connecting to Nginx
Duration: 00:00 | DP | 2025-12-08 23:57:30Docker Exec Mastery: The Right Way to Run Commands in Containers
Duration: 00:00 | DP | 2026-01-08 08:07:44How to Fix the "tsx: not found" Error During Vue Vite Builds in Docker
Duration: 00:00 | DP | 2026-01-10 08:10:19Decoding `realpath: command not found` and Its Chained Errors on macOS
Duration: 00:00 | DP | 2025-11-19 12:45:02Recommended
Master Sublime Text Code Folding: The Ultimate Shortcut Guide to Unfold/Fold Blocks Instantly
00:00 | 123Code folding is essential for navigating complex f...
Ultimate Guide: Fixing the PostgreSQL `could not find driver` Error in a Docker PHP Environment
00:00 | 90Encountering the "could not find driver" error whe...
The PHP Static Property Trap: Why You Cannot Initialize With a Function Call
00:00 | 93Refactoring a hardcoded static property in PHP, su...
From Guzzle to Native cURL: A Masterclass in Refactoring a PHP Translator Component
00:00 | 103Learn how to replace Guzzle with native PHP cURL f...