🎯 Advanced Runtime Guide
Passing Arguments to process.sh
Any argument passed after the image name at runtime is captured by the baseimage and then handled in one of two ways:
- If at least one service
process.shis run, the same argument list is appended to every runningprocess.sh. - If no service
process.shis run, the argument list is treated as a standalone command to execute instead. - If no service is run and no command is provided, Bash is started automatically.
Examples:
If my-image has one linked service, its process.sh is executed as:
In a multi-process image, the same arguments are passed to every running service process:
This means:
/container/services/service-a/process.sh --verbose
/container/services/service-b/process.sh --verbose
Use this only when the same runtime arguments make sense for all running services.
Controlling Container Lifecycle Steps
The entrypoint lifecycle has three steps:
startupprocessfinish
Behavior by step:
startup: runs--pre-startup-cmdcommands, then every running servicestartup.shin service priority order.process: runs--pre-process-cmdcommands, then the main command and/or every running serviceprocess.sh.finish: runs--pre-finish-cmdcommands, then every running servicefinish.shin service priority order.exit: always runs--pre-exit-cmdbefore the container exits.
Useful flags:
--skip-startup,--skip-process,--skip-finish--step startup|process|finish--exec service-name--skip service-name--skip-all
Important details:
.priorityaffectsinstall.sh,startup.sh, andfinish.sh..prioritydoes not affectprocess.sh; all running service processes are started concurrently.--step processruns only the process step and skips startup and finish.- If
--skip-processis used together with--bash, process services are skipped but Bash still runs. - Environment files are loaded before lifecycle pre-commands and service scripts, unless
--skip-env-filesis used.
Running Extra Commands
There are two distinct ways to run extra commands.
1. Pre-step commands
Use:
--pre-startup-cmd--pre-process-cmd--pre-finish-cmd--pre-exit-cmd
Each flag can be repeated. Commands are split with shell-like parsing, but they are not executed through a shell unless you explicitly call one yourself.
Example:
docker run --rm my-image \
--pre-startup-cmd 'mkdir -p /run/container/cache' \
--pre-process-cmd 'sh -c "echo ready > /tmp/health"'
If you need pipes, redirects, shell expansion, or compound shell syntax, wrap the command with sh -c or bash -c.
2. Run a command alongside services
Use:
This starts Bash in parallel with running service processes.
If no service process is run:
- arguments after the flags are run as a command
--bashcan still be used to run Bash alongside that command
This is mainly useful for debugging and container inspection.
Running Multi-Process Images in Separate Containers
The same image can be used either as:
- one multi-process container
- several single-purpose containers
Use container services link during build to define the default linked services. At runtime, narrow the selection with --exec or remove services with --skip.
Examples:
Runs all linked services.
Runs only the nginx service lifecycle.
Runs only the php-fpm service lifecycle.
This pattern is useful when:
- you want one build artifact but different deployment topologies
- you want to split a multi-process development image into separate production containers
- you want to debug one service without starting the others
Keep in mind:
- startup and finish scripts still run for the services being run only
- process arguments are shared across all running services
- restart behavior changes with the number of running process scripts
By default:
- single running process: restart is disabled
- multiple running processes: restart is enabled
Override this with --restart=true or --restart=false.