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?


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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.