Docker Community Forums

Share and learn in the Docker community.

How can I get the docker run parameters inside a container?


(Pebbe) #1

How can I test inside a container what run parameters were used to start the container?


(David Maze) #2

This seems a little bit tautological: the parameters used to start the container become the command-line parameters to the program the container runs, so it looks at its $1 or sys.argv or whatever.

A typical technique is to use a shell script to do some initial setup, and that can also do things with the arguments:

#!/bin/sh
# I am entrypoint.sh.
if [ "$1" = "the_daemon" ]
  echo "You are about to run the_daemon.  Arguments:"
  echo "$@"
fi
exec "$@"
# I am the Dockerfile.
FROM ubuntu:16.04
RUN apt-get install the_daemon && apt-get clean
COPY entrypoint.sh /
ENTRYPOINT /entrypoint.sh
CMD the_daemon

Does that help?


(Pebbe) #3

I don’t mean the parameters to the program run in Docker, but the parameters to docker run itself, the parameters you see when you run docker run --help


(Nickeyzeng) #4

hi @pebbe, did you find how solve this issue.
I have same requirement as you.