Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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
like image 495
Alex Avatar asked Nov 20 '17 09:11

Alex


People also ask

Can not open sh file?

How can I fix it? You might want to use an absolute path or a path relative to the directory from which you run the python program. As it is currently, sh is going to look for run.sh in its $PATH , which might differ from your execution context's $PATH .

What is sh command in docker?

The SHELL instruction allows the default shell used for the shell form of commands to be overridden. The default shell on Linux is ["/bin/sh", "-c"] , and on Windows is ["cmd", "/S", "/C"] . The SHELL instruction must be written in JSON form in a Dockerfile.

How do I run a file in a docker container?

To use the docker exec command, you will need a running Docker container. If you don't already have a container, start a test container with the following docker run command: docker run -d --name container-name alpine watch "date >> /var/log/date. log"


1 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
like image 189
Liam Roberts Avatar answered Oct 10 '22 21:10

Liam Roberts