22

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
Alex
  • 41,580
  • 88
  • 260
  • 469
  • Have you tried using `/bin/sh` as it is proposed here: [Running a script inside a docker container using shell script](https://stackoverflow.com/questions/31578446/running-a-script-inside-a-docker-container-using-shell-script)? – tgogos Nov 20 '17 at 09:46
  • Does not explain the problem I have with a simple `ls`... – Alex Nov 20 '17 at 09:51
  • What version/platform of Docker are you running? What are the permissions on the volume source, including uid/gid on the host? – BMitch Nov 20 '17 at 09:56
  • What is the `ENTRYPOINT` of your image? Is it the default (`/bin/sh -c`)? If not, maybe this is why `ls` is failing. – tgogos Nov 20 '17 at 10:06
  • Regarding the permissions: No idea – Alex Nov 20 '17 at 11:03
  • @Alex i am also facing same problem ..is u have solved this issue please ans here https://stackoverflow.com/questions/53408196/sh-0-cant-open-mysql2sqlite – Gaju Kollur Nov 21 '18 at 12:36
  • 1
    If you solved the problem, answer it. If not, provide more details of your environment to allow us to figure out what is happening (eg. a full Dockerfile to allow us reproduce your problem). Anyway, did you try to run `pwd` to check what is the working dir? `whoami` may be useful also. – Diego Queiroz Jun 14 '20 at 14:01
  • Just to be sure: you are mounting `the current (host-)directory to the docker's /selenium` (so a direct subdir of root) but your dockerfile switch the workdir to "'/work" (which also is a direct subdir of root) but you stated that the "start.sh" is contained inside the /selenium. So, is it possible that you are in "/work" searching for a file that is actually in /selenium/start.sh"? – Mattia Galati Jul 19 '20 at 20:54

3 Answers3

2

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
Mike
  • 14,010
  • 29
  • 101
  • 161
Liam Roberts
  • 924
  • 7
  • 7
0

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.

Shaqil Ismail
  • 1,794
  • 1
  • 4
  • 5
-5
  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.
Victor
  • 2,450
  • 2
  • 23
  • 54
santosh ghimire
  • 169
  • 1
  • 10
  • Victor thanks for editing but i think isn't sufficient for that. furthermore they will face the problems. its better to say give the permission to .sh file you want to open or execute. – santosh ghimire Jul 10 '20 at 02:53