Practical Guide: Translating Complex Docker Compose to Docker Run Commands

Published: 2026-07-29
Author: DP
Views: 1
Category: Docker
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