Reputation: 56
I have Dockerfile with entrypoint:
ENTRYPOINT ["bash", "-c", "source /code/entrypoint.sh | ts '[%Y-%m-%d
%H:%M:%S]' &>> /output/stderr.log"]
and command in entrypoint.sh:
fmriprep /input /output participant --fs-license-file
/opt/freesurfer/license.txt --use-aroma --ignore fieldmaps --n_cpus 12 --
force-bbr --participant_label "${ids[@]}" -w /output
How could i set flags for command inside entrypoint for example add flag --some_flag to fmriprep command to run it with
docker run my_image --some-flag
Upvotes: 0
Views: 6370
Reputation: 158778
If you use the JSON-array form of ENTRYPOINT
, then everything in CMD
is passed as command-line arguments to the entrypoint.
I would encourage not trying to write complex scripts inline in a Dockerfile
or docker-compose.yml
file. Write an ordinary script, COPY
it into the image, and make that script the ENTRYPOINT
. It can refer to the shell variable "$@"
to run its CMD
.
For example, I could refactor your script into:
#!/bin/bash
# I am /entrypoint.sh
"$@" | ts '[%Y-%m-%d %H:%M:%S]' &>> /output/stderr.log
#!/bin/bash
# I am /run.sh
fmriprep /input /output participant --fs-license-file /opt/freesurfer/license.txt --use-aroma --ignore fieldmaps --n_cpus 12 --force-bbr --participant_label "${ids[@]}" -w /output $EXTRA_OPTS
And then write a Dockerfile:
...
COPY entrypoint.sh run.sh /
ENTRYPOINT ["/entrypoint.sh"]
CMD ["/run.sh"]
And then you would get to run:
docker run my_image /run.sh --some-flag
You would also get to run ordinary debugging commands like:
docker run --rm -it my_image /bin/sh
docker run --rm my_image cat /run.sh
In this specific example I would probably rely on some external system to format and capture the log messages and not try to do it inside the container. Routing Docker container logs to logstash, for instance, is a pretty typical setup.
Upvotes: 0
Reputation: 3183
Pass an environment variable:
docker run -e flag=somevalue my_image
You can access flag via $flag
inside your Dockerfile
which you can pass to your script
Upvotes: 0
Reputation: 1706
You should be able to pass some environnement variable from you run command to your CMD before the "cmd" is triggered. To do such, try using the '-e' clause this way (not tested, but should work):
docker run my_image -e 'EXTRA_OPTS=--some-flag'
and in your command :
fmriprep /input /output participant --fs-license-file
/opt/freesurfer/license.txt --use-aroma --ignore fieldmaps --n_cpus 12 --
force-bbr --participant_label "${ids[@]}" -w /output $EXTRA_OPTS
That's the basic idea
Upvotes: 1