How to run `source` with `docker exec`?

21,584

Source is not an executable (source is a bash shell built-in command that executes the content of the file passed as argument)

You should run source like this:

docker run --rm -ti _image_name_ bash -c 'source FILE'
Share:
21,584

Related videos on Youtube

k0pernikus
Author by

k0pernikus

I am Philipp Kretzschmar, a backend developer from Hamburg working at Demvsystem. You can find me on github. Or twitter. My main weapons of choice are: php TypeScript (I don't want to write plain JavaScript anymore) and nodejs I play around with: Java python rust I used to write some scala, but for now I don't want to go there anymore. I feel most comfortable on a unix-like system featuring a powerful bash. (This excludes MacOS.) I love to code within JetBrains's flavored IDEs, e.g. IntelliJ, PhpStorm, WebStorm and using the IdeaVim plugin and having a docker-compose stack to develop on.

Updated on September 18, 2022

Comments

  • k0pernikus
    k0pernikus almost 2 years

    I wanted to source a file in a docker container running Ubuntu without going inside the container.

    I used to:

    docker exec -it CONTAINER_ID bash
    source FILE
    

    Now I wanted to do:

    docker exec -it CONTAINER_ID source FILE
    

    and was surprised that the error pops up:

    exec: "source": executable file not found in $PATH
    

    True enough I realized that source does not seem to be your standard command, as I cannot locate it via which source. ls behaves nicely.

    What kind of thing is this source command anyway, and how to execute it via docker exec -it?

  • verboze
    verboze over 6 years
    ah! thank you! I forgot, docker is not executing commands with bash, but instead with sh.