Simply run
docker exec -it my_container \
bash -c "source path_to/custom.sh; foo"
You can check more details here:
Commands separated by a ‘;’ are executed sequentially; the shell waits for each command to terminate in turn. The return status is the exit status of the last command executed.