Containerized Multi-Application Deployment: A Practical Guide
This guide explains why manually starting individual containers breaks down for real applications, and how declarative multi-container orchestration solves the problem. It covers the core structure of an orchestration configuration file, the correct way to handle dependencies and startup order with health checks, and the day-to-day operations that matter most. You will also find a checklist of common beginner mistakes and practical advice for moving from single-host deployment toward a repeatable delivery pipeline. The focus is on writing one correct, versionable configuration and reusing it, rather than memorizing commands.
1. Why Manually Starting a Single Container Does Not Hold Up in Production
Most people start with containers the same way: one command launches one service, there are only a few parameters, and everything looks fine. The problems appear once the business gets more complex. A typical web application needs at least three types of processes working together: the application process that exposes the API, a database for persistence, and a cache for acceleration and session storage. If you keep starting each of them by hand, four structural problems show up immediately.
Parameter growth with no traceability. Manual startup requires explicitly declaring port mappings, environment variables, data mount points, reconnection policies, log drivers, and many other parameters. The command quickly becomes unmanageable, and those parameters live only in one person’s shell history on one machine. Nobody can say for sure what parameters production is actually running with.
Environment drift. Switch machines or hand the work to a colleague, and every parameter has to be reproduced from scratch. Missing a single environment variable can cause a startup failure or unexpected behavior. This is the main source of “it works locally but not in production.”
Dependency order enforced by memory. The database must finish initialization before the application can create its tables; the cache must be ready before the application starts, or the app can be knocked over by connection failures in the first moments of startup. With manual startup, this ordering depends entirely on what the operator remembers.
Fragmented lifecycle management. Stopping, restarting, checking status, and scaling each require remembering the identifier of every process, and rolling back as a whole after a failure is difficult.
The core idea of declarative multi-container orchestration is to move “how to run” out of command history and into a versionable configuration file: the tool creates the network, mounts the data volumes, starts containers according to their dependencies, and exposes a single entry point for lifecycle operations. The direct benefits are repeatable deployments, aligned environments, reviewable changes, and rollback when things break.
2. Core Structure of the Configuration File
Orchestration configuration files typically use YAML syntax and consist of several top-level blocks, each with a clear, non-overlapping responsibility.
- Services (
services): declares the process units to run, including image, startup arguments, environment variables, port mappings, data mounts, health checks, resource limits, and restart policies. This is the largest section of the file. - Networks (
networks): declares the communication domains between services. By default, the orchestration tool creates an internal network for the same configuration, and services can reach each other directly by service name without caring about container addresses. - Volumes (
volumes): declares the data that must survive across container lifecycles, decoupling persistent data from the container’s writable layer. - Configs and secrets (
configs/secrets): used to inject sensitive information and ordinary configuration separately, so passwords never end up baked into an image or written as plaintext environment variables.
One widely repeated misconception needs correcting first: the top-level version declaration field that almost every early tutorial includes is deprecated in modern orchestration specifications and kept only for backward compatibility. Continuing to write it produces nothing but an obsolete notice at execution time and brings no functional benefit. To determine whether a field is still valid, the reliable approach is to check the official specification for the version you are using, not to copy an old post.
A minimal but complete example structure looks like this (illustrative; refer to the official specification for field details):
services:app:image: registry.example.internal/app:1.4.0environment:APP_ENV: productionDB_HOST: dbdepends_on:db:condition: service_healthyports:- "8080:8080"restart: unless-stoppeddb:image: registry.example.internal/db:16environment:POSTGRES_DB: appdbvolumes:- dbdata:/var/lib/postgresql/datahealthcheck:test: ["CMD-SHELL", "pg_isready -U app"]interval: 10sretries: 5cache:image: registry.example.internal/cache:7command: ["--appendonly", "yes"]volumes:dbdata:
Three design points here are easy to overlook. First, services address each other by service name, so the database address on the application side should be the service name rather than a fixed address; this is the prerequisite for a portable configuration. Second, data volumes must be declared explicitly. The container’s writable layer is lost as soon as the container is deleted, so putting database files there puts the data at risk. Third, images should use explicit version tags rather than floating tags; otherwise the content pulled at different times on different machines may differ, and failures become hard to reproduce.
3. Understanding Dependencies and Startup Order Correctly
A dependency declaration controls startup order; it does not automatically mean the service is available. Declaring a dependency only guarantees that the depended-on container is created and started first. It cannot guarantee that the process inside has finished initializing. If the database container is running but still performing startup recovery, the application’s connection attempt will still fail.
The reliable approach has two layers. The first layer is to configure a health check for the depended-on service, upgrading “the process exists” to “the service is capable,” and then have the dependent service wait for the healthy state. The second layer is for the application itself to have retry and backoff logic, treating a connection failure as a recoverable temporary state. Only with both layers in place are timing issues at the orchestration layer and the application layer covered at the same time.
It is worth stressing that a restart policy cannot replace a health check. Unconditional restarts turn deterministic failures such as configuration errors or port conflicts into infinite loops, which both hides the problem and consumes resources. A sensible combination is: a restart policy with a limited number of attempts for processes that can self-heal, health checks for critical services, and deterministic errors surfaced in logs and status.
4. High-Frequency Operations and Day-to-Day Maintenance
The value of an orchestration tool concentrates in a few unified entry points: starting the whole set of services, checking running status, following logs, recreating some services in the background, and stopping everything while cleaning up resources. Once you master these actions, daily operations rarely require handling containers one by one again.
A few practices are worth turning into habits:
- Recreate instead of restart after a configuration change. After changing the image, environment variables, or mount relationships, restarting the process alone will not apply the new configuration; the tool needs to recreate the containers according to the new configuration.
- Validate before executing. Most orchestration implementations offer configuration validation and expansion preview, so you can confirm the parameters that will actually take effect before applying them and avoid carrying syntax errors into production.
- Filter logs by service. When multiple services output at the same time, mixed logs are almost unreadable. Filtering by service and narrowing down by time range is far more efficient.
- Distinguish stopping from deleting. Stopping alone keeps containers and data volumes; adding cleanup removes the data volumes as well. The latter is irreversible and must be confirmed before running.
- Script the common actions. Turning validation, startup, and status checks into a unified entry-point script significantly reduces human omissions.
5. Checklist of Common Beginner Mistakes
- Treating the version declaration as mandatory and copying an outdated template.
- Using floating image tags, which leads to inconsistent content across environments.
- Putting persistent data in the container’s writable layer, so data is lost as soon as the container is recreated.
- Declaring dependencies without health checks, so the application fails to connect at the moment it starts.
- Writing port mappings as an indiscriminate wide range, which wastes resources and enlarges the exposure surface.
- Writing passwords in plaintext into the configuration file and committing it to a code repository; use secret injection or external configuration management instead.
- Leaving resource limits unset at the orchestration layer, which is required for long-running stability, so a single misbehaving service can drag down the whole machine; set resource limits for critical services.
- Ignoring the log driver and rotation configuration, so logs fill the disk and trigger a machine-wide failure.
6. Moving From a Single Host to a Deliverable Environment
Once the configuration is stable, the next step is to bring it into the delivery process: put the configuration under version control and review changes; pin image tags at build time and retain the artifacts; run a full startup and health check in a pre-production environment before deployment; and after release, connect to a unified logging service and monitoring with alerts, setting thresholds for container status, API success rate, and resource usage.
If the business keeps growing, single-host orchestration will hit a bottleneck. At that point you can migrate to managed container platform capabilities, letting the platform handle scheduling, scaling, and self-healing, while most of the service definitions, environment variables, and dependency and health check designs in the orchestration configuration file can be reused. This also shows the value of writing the configuration properly from the start: it is both a deployment specification and an asset for future migration.
For cloud deployments, you can combine general-purpose capabilities as needed: a container platform for runtime and elasticity, object storage for static assets and backups, a message queue to decouple asynchronous tasks, and logging plus monitoring and alerting for observability. Baidu AI Cloud offers the same category of general-purpose capability combinations in these scenarios; refer to the official documentation for specific specifications and integration methods.
7. Summary
The complexity of multi-container deployment does not come from containers themselves but from the lack of a unified, versionable way to describe them. Writing services, networks, data volumes, dependencies, and health checks into one compliant configuration, combined with a few fixed actions—validation, recreation, log filtering, and status checks—compresses repetitive command typing into define once, reuse many times. Get the configuration right first, then talk about elasticity and scale; that is the order that saves the most time on this path.
