2

I am using a private docker hub repository https://hub.docker.com/u/privaterepoexample/, after which I have built my docker image using the commands below:

docker login
docker build -t privaterepoexample/sre:local .
docker tag 85cf9475bc1c privaterepoexample/sre
docker push privaterepoexample/sre

The output of docker build which shows login.sh added to container:

Executing busybox-1.29.3-r10.trigger
OK: 85 MiB in 57 packages
Removing intermediate container 12fd67450dfc
 ---> e9ca0b9e4ac4
Step 5/7 : WORKDIR /opt
---> Running in ce881ede94aa
Removing intermediate container ce881ede94aa
---> 2335b4f522ac
Step 6/7 : ADD login.sh /opt
---> 2aabf1712153
Step 7/7 : CMD ["chmod 755 login.sh  && ./login.sh"]
 ---> Running in 8ec824d4e561
Removing intermediate container 8ec824d4e561
 ---> c97a4ad61578
Successfully built c97a4ad61578
Successfully tagged privaterepoexample/sre:local

The Dockerfile below is built successfully and login.sh is added successfully:

FROM ubuntu:16.04


RUN apt-get update && apt-get install -y \
curl

FROM openjdk:8-jre-alpine

RUN apk --no-cache add curl


WORKDIR /opt


ADD login.sh /opt


CMD ["chmod 755 login.sh  && ./login.sh"]

Now here comes with my problem, when I execute docker run like below, I get the error:

docker run -i privaterepoexample/sre 

 docker: Error response from daemon: OCI runtime create failed: container_linux.go:345: starting container process caused "exec: \"chmod 755 login.sh  && ./login.sh\": stat chmod 755 login.sh  && ./login.sh: 
no such file or directory": unknown.

but why does it say no such file? given when I go inside the docker container, I can see the login.sh script with the command below:

$ docker run -it   
privaterepoexample/sre /bin/sh
/opt # ls
login.sh
/opt # cat login.sh 
#!/bin/sh
# Black Box Tester!
content=$(curl  --location --request POST  
"https://api.platform.abc.com/auth/oauth/token" --header    
'Content-Type: application/x-www-form-urlencoded' \
 --header 'Authorization: Basic ' --data-raw 'grant_type=password&
[email protected]&password=fJff'| jq -r 
'.domain_id' )
 if [ $content = abc ]
     then
          echo “Valid Login Token”
else
          echo “invalid url”
fi
/opt # exit
1
  • beyond your main question, note that your Dockerfile is suboptimal, because it uses the multi-stage build feature of Docker (namely, you have several FROM in your Dockerfile), while it seems this feature is unneeded for your use case. Thus, you may want to remove the first two lines of your Dockerfile and start with FROM openjdk:8-jre-alpine or even with FROM alpine if you don't need a (Java) JRE. Commented Mar 7, 2020 at 22:14

1 Answer 1

6

You get the error no such file or directory because you are using a so-called CMD in exec form in an unexpected way.

You can fix your Dockerfile in several ways, e.g.:

  • either use a CMD in shell form:

    CMD chmod 755 login.sh && ./login.sh
    
  • or keep a CMD in exec form (which is often a good idea), but ensure the first argument of the JSON array is a program, not a composite command. You can do this e.g. by running chmod 755 … beforehand, at build time:

    ADD login.sh /opt
    RUN chmod 755 login.sh
    CMD ["./login.sh"]
    

For more information on the CMD command and its brother command ENTRYPOINT, see also this other SO answer: CMD doesn't run after ENTRYPOINT in Dockerfile

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.