command not found in pipenv path - jenkins

Edit: This is solved, see answer below
I'm trying to deploy some software using Docker / Jenkins for the first time and I'm running into some issues with the paths.
This is the current Dockerfile:
WORKDIR /usr/src/app
COPY ./ .
RUN pip install pipenv
RUN pipenv install --ignore-pipfile
ENV PATH="${PATH}:/usr/src/app"
RUN pipenv run echo $PATH
RUN pwd
RUN ls
RUN pipenv run whereis run
RUN pipenv run run
When I try to build the docker image using Jenkins, I get the following output:
09:19:48 ---> Running in ff1a52b2e299
09:19:48 Removing intermediate container ff1a52b2e299
09:19:48 ---> 67355de18e72
09:19:48 Step 7/11 : RUN pipenv run echo $PATH
09:19:48 ---> Running in 5cb904118910
09:19:49 /usr/local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/src/app
09:19:49 Removing intermediate container 5cb904118910
09:19:49 ---> 0df62985c94d
09:19:49 Step 8/11 : RUN pwd
09:19:49 ---> Running in 4e79f53b581f
09:19:49 /usr/src/app
09:19:50 Removing intermediate container 4e79f53b581f
09:19:50 ---> 563ab4218eba
09:19:50 Step 9/11 : RUN ls
09:19:50 ---> Running in fbc7670633d1
09:19:50 Dockerfile
09:19:50 Jenkinsfile
09:19:50 Pipfile
09:19:50 Pipfile.lock
09:19:50 README.md
09:19:50 alembic.ini
09:19:50 run.bat
09:19:50 run.sh
09:19:50 trendanalyse
09:19:51 Removing intermediate container fbc7670633d1
09:19:51 ---> 02a4b76defd0
09:19:51 Step 10/11 : RUN pipenv run whereis run
09:19:51 ---> Running in 70d5448e29b1
09:19:51 run: /usr/src/app/run.bat /usr/src/app/run.sh /usr/src/app/run.bat /usr/src/app/run.sh
09:19:52 Removing intermediate container 70d5448e29b1
09:19:52 ---> 455fc44688ce
09:19:52 Step 11/11 : RUN pipenv run run
09:19:52 ---> Running in b25bf9d5f818
09:19:52 [91mError: the command run could not be found within PATH or Pipfile's [scripts].
09:19:53 [0mThe command '/bin/sh -c pipenv run run' returned a non-zero code: 1
I don't see what's wrong, the run.sh file is in the current path, not sure why it won't run. It's working locally on my Windows machine, maybe it's some difference between Windows / Linux that I'm not seeing?
Thanks!

There were two issues with the Dockerfile, I needed to add the line
RUN chmod +x run.sh
Additionally, I had to change
RUN pipenv run run
to
RUN pipenv run run.sh
(I think this is due to differences in Windows / Linux). Now it works :)

Related

Ubuntu Docker Build - facing error during run at ENTRYPOINT "No such file or directory"

I have a working build that I am trying to dockerise. This is my dockerfile, I added the "pwd" and "ls -l" to see if the build is copied correctly and it is. However when I try to run "docker run " I get the error "No such file or directory. Please let me know what I might be doing wrong. Appreciate your help.
Dockerfile
FROM <base image>
WORKDIR /app
RUN echo 'List all files'
RUN pwd
RUN ls -l
COPY src/mysolution-linux-amd64 /app/
RUN ls -l
ENTRYPOINT ["/app/mysolution-linux-amd64"]
I have tried ENTRYPOINT with both "./mysolution-linux-amd64" and "/app/mysolution-linux-amd64" but both fail when I run.
Output during Docker build
Sending build context to Docker daemon 1.014GB
Step 1/8 : FROM <base image>
---> 3ed27f7c19ce
Step 2/8 : WORKDIR /app
---> Running in 1b273ccccd22
Removing intermediate container 1b273ccccd22
---> 92560bbb67eb
Step 3/8 : RUN echo 'List all files'
---> Running in faddc1b6adfd
List all files
Removing intermediate container faddc1b6adfd
---> b7b2f657012e
Step 4/8 : RUN pwd
---> Running in 8354a5a476ac
/app
Removing intermediate container 8354a5a476ac
---> 204a625b730b
Step 5/8 : RUN ls -l
---> Running in 0d45cf1339d9
total 0
Removing intermediate container 0d45cf1339d9
---> 6df6451aef44
Step 6/8 : COPY src/mysolution-linux-amd64 /app/
---> 44ac2f066340
Step 7/8 : RUN ls -l
---> Running in d17ec6b0c7af
total 11460
-rwxrwxr-x 1 root root 11734780 Nov 26 04:25 mysolution-linux-amd64
Removing intermediate container d17ec6b0c7af
---> 56a879ef9440
Step 8/8 : ENTRYPOINT ["/app/mysolution-linux-amd64"]
---> Running in 33bea73f14dc
Removing intermediate container 33bea73f14dc
---> ef794fe310bc
Successfully built ef794fe310bc
Successfully tagged newtech/mysolution:latest

Whs is my init.sh not found after succeful build?

My Dockerfile
FROM alpine:latest
WORKDIR /usr/src/app
COPY ./init.sh /usr/src/app
RUN chmod +x init.sh
CMD ["sh","-c","init.sh"]
Build goes OK
docker build . -t test
Sending build context to Docker daemon 3.072kB
Step 1/5 : FROM alpine:latest
---> e66264b98777
Step 2/5 : WORKDIR /usr/src/app
---> Running in 1ff4467854af
Removing intermediate container 1ff4467854af
---> 6b4f1fa4ca1c
Step 3/5 : COPY ./init.sh /usr/src/app
---> e61e55063baa
Step 4/5 : RUN chmod +x init.sh
---> Running in ae3724c0f595
Removing intermediate container ae3724c0f595
---> 3c2cd99a30b9
Step 5/5 : CMD ["sh","-c","init.sh"]
---> Running in 9df8c7d70e38
Removing intermediate container 9df8c7d70e38
---> bd9c9af6380d
Successfully built bd9c9af6380d
Successfully tagged test:latest
I got this
docker run -it test
sh: init.sh: not found
Why?
Use ./init.sh to execute the script, provided that the shell script has a proper shebang like #!/bin/sh on the top:
FROM alpine:latest
WORKDIR /usr/src/app
COPY ./init.sh /usr/src/app
RUN chmod +x init.sh
CMD ["sh", "-c", "./init.sh"]
Note that it's actually not necessary, and can be shortened as CMD ./init.sh.

docker container couldn't locate file but file is present

I am trying to package gotty into a Docker container but found a weird behavior.
$ tree
.
├── Dockerfile
├── gotty
└── gotty_linux_amd64.tar.gz
Dockerfile:
FROM alpine:3.11.3
RUN mkdir -p /home/gotty
WORKDIR /home/gotty
COPY gotty /home/gotty
RUN chmod +x /home/gotty/gotty
CMD ["/bin/sh"]
The image was built without issue:
[strip...]
Removing intermediate container 0dee1ab645e0
---> b5c6957d36e1
Step 7/9 : COPY gotty /home/gotty
---> fb1a1adec04a
Step 8/9 : RUN chmod +x /home/gotty/gotty
---> Running in 90031140da40
Removing intermediate container 90031140da40
---> 609e1a5453f7
Step 9/9 : CMD ["/bin/sh"]
---> Running in 30ce65cd4339
Removing intermediate container 30ce65cd4339
---> 099bc22ee6c0
Successfully built 099bc22ee6c0
The chmod changed the file mode successfully. So /home/gotty/gotty is present.
$ docker run -itd 099bc22ee6c0
9b219a6ef670b9576274a7b82a1b2cd813303c6ea5280e17a23a917ce809c5fa
$ docker exec -it 9b219a6ef670 /bin/sh
/home/gotty # ls
gotty
/home/gotty # ./gotty
/bin/sh: ./gotty: not found
Go into the container, the gotty command is there. I ran it with relative path. Why the not found?
You are running into one of the more notorious problems with Alpine: Musl, instead of glibc. Check out the output of ldd gotty. Try adding libc6-compat:
apk add libc6-compat
and see if that fixes it.

dockerfile Add file can not be found

Server Version: 18.03.1-ce ,RHEL 7.2 .Here is my dockerfile:
FROM openjdk:8-jdk-alpine
ENV http_proxy http://192.168.156.25:3128
ENV https_proxy http://192.168.156.25:3128
RUN apk update && apk upgrade && apk add netcat-openbsd
RUN mkdir -p /usr/local/licensingservice
ADD #project.build.finalName#.jar /usr/local/licensingservice/
ADD run.sh run.sh
RUN chmod +x run.sh
CMD ./run.sh
it build without error:
---> Using cache
---> 8fa60876c229
Step 5/9 : RUN mkdir -p /usr/local/licensingservice
---> Using cache
---> bca46b1256e1
Step 6/9 : ADD licensing-service-0.0.1-SNAPSHOT.jar /usr/local/licensingservice/
---> a66979ed3755
Step 7/9 : ADD run.sh ./run.sh
---> 95b492565374
Step 8/9 : RUN chmod +x run.sh
---> Running in eec3075c30f3
Removing intermediate container eec3075c30f3
---> 96a2d7b89b80
Step 9/9 : CMD ./run.sh
---> Running in c338e9d33371
Removing intermediate container c338e9d33371
---> 324d5a83cf84
ProgressMessage{id=null, status=null, stream=null, error=null, progress=null, progressDetail=null}
Successfully built 324d5a83cf84
Successfully tagged johncarnell/tmx-licensing-service:chapter4
but docker run -it 324d5a83cf84:
/bin/sh: ./run.sh: not found
I debug using docker run --rm -it 324d5a83cf84 cat ./run.sh,it print the file well.
run.sh:
#!/bin/sh
echo "hello1"
I suspect you are working on Windows and you are using the default Windows newline: CR LF. Change to LF in your run.sh and it will work like a charm.
But how to do that you ask? Open run.sh in Notepad++ and look at the bottom right of the window. Click on Windows (CR LF) and select Unix (LF).

Docker glide not found

Docker is not able to find glide, which was installed successfully in steps 3 and 4 (below). I ran
docker build .
This is the first part of the Dockerfile:
FROM golang:latest as builder
# Set up workdir
WORKDIR /go/src/github.com/cayleygraph/cayley
# Restore vendored dependencies
RUN sh -c "curl https://glide.sh/get | sh"
COPY glide.* ./
RUN glide install
But it failed on step 5 with this error:
docker build .
Sending build context to Docker daemon 65.18MB
Step 1/29 : FROM golang:latest as builder
---> 1a34fad76b34
Step 2/29 : WORKDIR /go/src/github.com/cayleygraph/cayley
---> Using cache
---> dd9a295edeed
Step 3/29 : RUN sh -c "curl https://glide.sh/get | sh"
---> Using cache
---> b432efdb0630
Step 4/29 : COPY glide.* ./
---> Using cache
---> 936b9f7837eb
Step 5/29 : RUN glide install
---> Running in b244dcff6576
/bin/sh: 1: glide: not found
The command '/bin/sh -c glide install' returned a non-zero code: 127
Installing glide worked, not sure why it's not finding the actual executable though. Any ideas?
Make glide executable as well, in the Dockerfile. And skip the / in your COPY statement. Try to add this before you try to run it.
RUN chmod +x <file>
Seems like the install process only download the executable

Resources