11

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?

1 Answer 1

16

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'
1
  • ah! thank you! I forgot, docker is not executing commands with bash, but instead with sh.
    – verboze
    Jan 18, 2018 at 16:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .