Skip to content

Docker entrypoint argument forwarding

Docker entrypoint argument forwarding is a technique used in containerized applications to ensure that arguments passed to the docker run command are correctly relayed to the application running inside the container^[400-devops-09-scripting-language-golang-introduction-part-4commandline-readme.md].

To achieve this, the container's ENTRYPOINT is typically set to a shell script rather than the executable binary itself^[400-devops-09-scripting-language-golang-introduction-part-4commandline-readme.md]. This wrapper script accepts the dynamic arguments and invokes the actual application program, forwarding the arguments along with it^[400-devops-09-scripting-language-golang-introduction-part-4commandline-readme.md].

Implementation

Wrapper Script

The core mechanism relies on a shell script, often named run.sh, which serves as the entry point^[400-devops-09-scripting-language-golang-introduction-part-4commandline-readme.md]. This script contains the logic to launch the main application using any arguments provided at runtime.

Shell Syntax

The forwarding behavior is implemented by invoking the binary followed by a specific shell variable. The standard syntax appends $@ to the command, which represents all the arguments passed to the script^[400-devops-09-scripting-language-golang-introduction-part-4commandline-readme.md].

Example run.sh:

#!/bin/sh

# Execute the binary named 'videos' passing along all arguments
videos $@

Dockerfile Configuration

In the Dockerfile, the script must be copied into the image and made executable^[400-devops-09-scripting-language-golang-introduction-part-4commandline-readme.md]. The ENTRYPOINT instruction is then set to point to this script^[400-devops-09-scripting-language-golang-introduction-part-4commandline-readme.md].

Example Dockerfile snippet:

COPY run.sh /
RUN chmod +x /run.sh
ENTRYPOINT [ "./run.sh" ]

Usage

Once the image is built with this configuration, users can pass arguments directly to the container run command^[400-devops-09-scripting-language-golang-introduction-part-4commandline-readme.md]. These arguments are intercepted by the ENTRYPOINT script and forwarded to the application logic.

Example:

docker run -it videos get --help

In this example, get --help are the arguments forwarded to the underlying videos application^[400-devops-09-scripting-language-golang-introduction-part-4commandline-readme.md].

Sources

^[400-devops-09-scripting-language-golang-introduction-part-4commandline-readme.md]