2

I have a docker container that has a shared volume with the host. The volume mounts in the root home folder. In that folder, I have a shell script I want to run once the container is up and running.

I was using this command:

docker exec -i localserver_web_1 sh /root/scripts/define_applications.sh

but I'm getting this response:

sh: 0: Can't open /root/scripts/define_applications.sh

The script is working fine when I run it from inside the container. It says it's in /root/scripts/. I have permissions set at 777. What could I be doing wrong?

Jon Schwartz
  • 168
  • 1
  • 11
  • this turned out to be a pebkac error, but @VonC 's answer helped me diagnose the problem and may be helpful to others. – Jon Schwartz Dec 10 '15 at 14:30

1 Answers1

2

Just to be sure, try and exec as root, with a tty, in a command shell:

docker exec -it -u root localserver_web_1 sh -c '/root/scripts/define_applications.sh'

If it does not work, check at least its presence and content through docker exec:

docker exec -it -u root localserver_web_1 sh -c 'ls -alrt /root/scripts'
docker exec -it -u root localserver_web_1 sh -c 'cat /root/scripts/define_applications.sh'

Also inspect the image to check its ENTRYPOINT (similar to the check for its CMD):

docker inspect --format='{{.Config.Entrypoint}}' <image:tag>

The OP Jon Schwartz confirms in the comments:

this was a pebkac error.
The script is actually called define-applications.sh, not define_applications.sh.
The cat line showed me my issue. When it could see the script through ls, I knew it should be able to get to it. When it couldn't cat out, I realized what happened.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • 1
    thanks so much you helped me solve my issue... unfortunately, this was a pebkac error. The script is actually called define-applications.sh not define_applications.sh The cat line showed me my issue. When it could see the script through ls, I knew it should be able to get to it. When it couldn't cat out, I realized what happened. oops. thanks! – Jon Schwartz Dec 10 '15 at 14:29
  • @JonSchwartz Great! I have included your conclusion in the answer for more visibility. – VonC Dec 10 '15 at 14:31