2

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.

John Kugelman
  • 349,597
  • 67
  • 533
  • 578
Vizag
  • 375
  • 2
  • 6
  • 22
  • check my answer if this work for u, if not then share your dockerfile please – Adiii Jun 25 '19 at 11:55
  • it very clear from the logs `error: Error: Output path must specify a valid, existing directory.`. I will recommend creating your container, and then run `docker exec -it test ash| bash -c "scan-Command> -s python -o ./reports info"` and then invesitigate the error. or share your dockerfile – Adiii Jun 25 '19 at 12:59
  • Hi Adiii, thank you for responding to my question. Ran below command after modifying as per your suggestion. ` $ docker run --rm -it --name test -v /root/tools:/var/local -s python -o ./reports info: Scan Starting... info: Logging to: '/Scan1.log' info: Current CLI Version: 2.x.x warn: Unable to check for CLI update. error: Error: Output path must specify a valid, existing directory.` Later Checked using `$ docker ps -a ` and there were no containers running. – Vizag Jun 25 '19 at 13:04
  • Ye got it will do it that way. And for the dockerfile, I am actualy pulling the image from a private repository directly hence I do not yet have the source Dockerfile. Thank you for your help Adiii. – Vizag Jun 25 '19 at 13:06
  • Glad to know it works. my pleasure @Vizag – Adiii Jun 25 '19 at 13:09

1 Answers1

3

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"
Adiii
  • 54,482
  • 7
  • 145
  • 148