0

I'm running my image like this:

docker run -v $PWD:/home/project -it aos /bin/bash -c "source source_me.sh && /bin/bash"

I wanted the script source_me to be sourced when entering. This script has some easy functions to be called with small names. However, in this case the source is not applied, because a new bash is started after the source.

Trying just

docker run -v $PWD:/home/project -it aos /bin/bash -c "source source_me.sh"

Simply returns because it finishes execution.

How can I automatically make the source stuff sourced so the user can use the commands when he enters the docker run?

Guerlando OCs
  • 1,886
  • 9
  • 61
  • 150
  • I think it's better to turn that into an ENTRYPOINT script, then this might help: [How to source an entry point script with Docker?](https://stackoverflow.com/q/56586562/2745495) – Gino Mempin Mar 05 '22 at 02:27
  • You can get Bash to source a specified file at startup, if it's interactive, by using the `--rcfile` option. So `/bin/bash --rcfile .../source_me.sh`. That stops the `.bashrc` file being run, so you may want to `source` it in `source_me.sh`. I guess it's also possible that you might need to use the `-i` option to `/bin/bash` to ensure that it it behaves fully as an interactive shell. – pjh Mar 05 '22 at 02:33
  • In the question @GinoMempin cites, note that there is a shell script towards the top of the question that is usable as the image `ENTRYPOINT`. I don't copy that script into my answer but it's an important part of the context for this question. – David Maze Mar 05 '22 at 11:44
  • @DavidMaze it runs the source script but I don't get the functions defined in the source script. It's as if it just runs but in a separate terminal. Can we reopen please? – Guerlando OCs Mar 05 '22 at 22:24

0 Answers0