How to fix "sh: 0: Can't open start.sh" in docker file?

Viewed 52189

I have created a docker image which contains the following CMD:

CMD ["sh", "start.sh"]

When I run the docker image I use the following command inside a Makefile

docker run --rm -v ${PWD}:/selenium $(DOCKER_IMAGE)

which copies the files from the current (host-)directory to the docker's /selenium folder. The files include files for selenium tests, as well as the file start.sh. But after the container has started, I get immediately the error

"sh: 0: Can't open start.sh"

Maybe the host volume is mounted inside docker after the command has been run? Anything else that can explain this error, and how to fix it?

Maybe there is a way to run more than one command inside docker to see whats going on? Like

CMD ["ls", ";", "pwd", ";", "sh", "start.sh"]

Update

when I use the following command i the Dockerfile

CMD ["ls"]

I get the error

ls: cannot open directory '.': Permission denied

Extra information

  • Docker version 1.12.6
  • Entrypoint: WORKDIR /work
3 Answers

Your mounting your volume to the /selenium folder in your container. Therefor the start.sh file isn't going to be in your working directory its going to be in /selenium. You want to mount your volume to a selenium folder inside your working directory then make sure the command references this new path.

If you use docker-compose the YAML-file to run the container would look something like this:

version: '3'

services:
  start:
    image: ${DOCKER_IMAGE}
    command: sh selenium/start.sh
    volumes:
      - .:/work/selenium

If you try and perform each step manually, using docker run with bash,

docker exec -it (container name) /bin/bash

It will be more easier and quicker to look at the errors, and you can change the permissions, view where the file is located, before running the .sh file and try again.

  1. Check the permission using ls -l.
  2. Give the permission 777 using sudo chmod 777 file_name.
  3. Repeat for other files you might find.
Related