# Running docker from a CommandLineTool

**URL:** <https://cwl.discourse.group/t/running-docker-from-a-commandlinetool/836>\
**Category:** CWL Questions\
**Created:** [October 10, 2023, 9:06am UTC](https://cwl.discourse.group/t/running-docker-from-a-commandlinetool/836 "2023-10-10T09:06:12Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![locos](https://avatars.discourse-cdn.com/v4/letter/l/bc8723/32.png) [@locos](https://cwl.discourse.group/u/locos)\
**Post date:** [October 10, 2023, 9:06am UTC](https://cwl.discourse.group/t/running-docker-from-a-commandlinetool/836/1 "2023-10-10T09:06:12Z")

</div>

I have the [same problem](https://cwl.discourse.group/t/forming-multiple-arguments-via-arguments/297), the code below doesn’t work:

```auto
baseCommand: [docker, run, -v, /data:/data, --user, $(id -u):$(id -g), image1:v1]

```

---

<div class="post-metadata">

**Author:** ![alexiswl](https://yyz2.discourse-cdn.com/free1/user_avatar/cwl.discourse.group/alexiswl/32/93_2.png) [@alexiswl](https://cwl.discourse.group/u/alexiswl)\
**Post date:** [October 10, 2023, 10:53pm UTC](https://cwl.discourse.group/t/running-docker-from-a-commandlinetool/836/2 "2023-10-10T22:53:19Z")

</div>

Hi Locos,

This probably could have been a comment on the [question you linked](https://cwl.discourse.group/t/forming-multiple-arguments-via-arguments/297).

Regardless, in order for someone to assist you, please provide a fully reproducible example (not just the base command attribute) along with any errors that you’re seeing along with what you’re expecting to run?

Speculating with the limited code above, I think you ought to put the docker components in the DockerRequirement section of your CWL CommandLineTool, i.e

```plaintext
requirements:
  DockerRequirement:
    dockerpull: image1:v1

```

The baseCommand section should then represent the script inside the docker container you are wanting to run. i.e

```auto
baseCommand: ["bash", "myscript.sh"]

```

cwltool will handle the `-v/--volume` parameters based off your inputs and most implementations will assign a rootless random uid for the `-u/--user` parameter.

---

<div class="post-metadata">

**Author:** ![mrc](https://yyz2.discourse-cdn.com/free1/user_avatar/cwl.discourse.group/mrc/32/3_2.png) [@mrc](https://cwl.discourse.group/u/mrc)\
**Post date:** [October 11, 2023, 6:53am UTC](https://cwl.discourse.group/t/running-docker-from-a-commandlinetool/836/3 "2023-10-11T06:53:52Z")

</div>

> [@alexiswl](#):
>
> This probably could have been a comment on the [question you linked](https://cwl.discourse.group/t/forming-multiple-arguments-via-arguments/297).

[Note: Locos’s question was originally a comment, but I moved their post to its own topic and added the link, so it could have its own answer and since so much time had passed since the original topic was answered. Thank you @alexiswl , as always, for helping out here!]

 ![image](https://global.discourse-cdn.com/free1/uploads/cwl1/original/1X/26425f9a605115918efa8775ae4c4d306e1485ee.png)

---

<div class="post-metadata">

**Author:** ![davidjsherman](https://yyz2.discourse-cdn.com/free1/user_avatar/cwl.discourse.group/davidjsherman/32/205_2.png) [@davidjsherman](https://cwl.discourse.group/u/davidjsherman)\
**Post date:** [January 5, 2024, 1:23pm UTC](https://cwl.discourse.group/t/running-docker-from-a-commandlinetool/836/4 "2024-01-05T13:23:05Z")

</div>

@alexiswl answers the real question, _how do I run a command that is inside an OCI image_?.  
Is it useful to add that the answer to the specific question, _how do I run docker …?_ is probably: **don’t**?

I would think that running `docker` as the baseCommand would be an antipattern to be avoided, since it hides the intention of the step, The true command can only be found by inspecting the Entrypoint property of the config object in the in the OCI image. The name of the image might reflect that but might not.

Asking the tool to run `docker` explicitly also hinders portability, since it imposes a strong infrastructure requirement about the runtime. Whereas by separating the requirement from the command, in the way @alexiswl explains, one can use any executor that can resolve the requirement of running an OCI image, whether or not it is docker or something else.

(In the question the OCI image name is fortunately an immutable part of the command. A generic `docker` command line tool would go against the [best practices](https://www.commonwl.org/user_guide/topics/best-practices.html#best-practices), where it is recommended to reify even variants of the same executable in separate command line tool.)
