Search code examples
dockerdocker-rundocker-entrypoint

Docker run command to achieve few steps with a single line of command


I am trying to run a docker command for achieving following steps with a single line of command.

A) Pulling a docker image,
B) Then starting the container,
C) Do a volume mount of a directory from host to launched container,
D) And then gives scan command, inside container to capture reports.

I could achieve steps a, b and c with this command.

$ docker run -d -it --name test -v /root/tools:/var/local <mydocker-image-registry>

But for the last step, D, ie., to run a scan inside the container and capturing reports, I am unable to add that piece of command to above command and get it working.

This below piece of command works independently but could not append to above line and get it working.

<scan> -s python -o ./reports

The container just started and exited when given below command

docker run -d -it --name test -v /root/tools:/var/local <mydocker-image-registry> <scan> -s python -o ./reports

Also did some basic search and tried to add an Entrypoint as below

docker run -d -it --name test -v /root/tools:/var/local <mydocker-image-registry> -- entrypoint <scan> -s python -o ./reports

But that didn't work either. Just got an error docker: Error response from daemon: OCI runtime create failed: container_linux.go:345: starting container process caused "exec: \"--\": executable file not found in $PATH": unknown.

Expecting to achieve all above 4 steps executed with single docker command and I get 'reports' populated with results.


Solution

  • As --entrypoints failed to work with <scan> -s python -o ./reports so as to result you got the error below, as there is no executable file in the path.

    docker: Error response from daemon: OCI runtime create failed: container_linux.go:345: starting container process caused "exec: \"--\": executable file not found in $PATH": unknown.
    

    So when you got the above error, here is the example in screenshot along with the comment.

    enter image description here

    So instead of the overding entry point, specify the 4 option as argument command to your docker run command.

    docker run --rm -dit --name test -v /root/tools:/var/local alpine ash -c "date"
    

    this will print the date and will exit.

    If you want to keep it running, then you have modified this a bit.

    docker run --rm -it --name test alpine ash -c "date; tail -f /dev/null"
    

    this will make container keep running with out doing any thing.

    Another example can be a python, printing hello world within one command.

     docker run --rm -it --name test python:3.6-alpine ash -c "echo \"print('Hello, world ')\" >> ab.py; python ./ab.py"