How to extend a Docker image that does not have sh binaries - docker

I am trying to extend this image https://hub.docker.com/r/hashicorp/waypoint-odr but I can't figure out how to apply any tasks.
Anything I try to run I get the same error ... starting container process caused: exec: "/bin/sh": stat /bin/sh: no such file or directory: unknown
here is an example of minimal Dockerfile
FROM hashicorp/waypoint-odr:latest
RUN pwd
output
Sending build context to Docker daemon 2.048kB
Step 1/2 : FROM hashicorp/waypoint-odr:latest
---> 60e7c50c52f0
Step 2/2 : RUN pwd
---> Running in 075af9b246f9
failed to create shim: OCI runtime create failed: container_linux.go:380: starting container process caused: exec: "/bin/sh": stat /bin/sh: no such file or directory: unknown
I've tried this as well RUN /bin/ash -c "pwd" but the result is the same.
Do you have any ideas on how I can approach this issue?

It's a bit of an unusual image. The shell is installed in /kaniko/bin, but the Docker SHELL hasen't been set, so it looks for the shell in /bin and fails because it can't find it. You can set the shell and then you should be able to run commands like normal.
FROM hashicorp/waypoint-odr:latest
SHELL ["/kaniko/bin/sh", "-c"]
RUN pwd

Related

NIFI custom image run error "../scripts/start.sh: no such file or directory"

I am trying to build a docker image using NIFI with a mysql java connector jar. Here is my Dockerfile code:
FROM apache/nifi:1.12.0
RUN mkdir /opt/nifi/nifi-current/custom-jar
WORKDIR /opt/nifi/nifi-current/custom-jar
RUN wget http://www.java2s.com/Code/JarDownload/mysql/mysql-connector-java-5.1.17-bin.jar.zip
RUN unzip mysql-connector-java-5.1.17-bin.jar.zip
The image builds without error, but when I try to run the image, I get this error:
docker: Error response from daemon: OCI runtime create failed: container_linux.go:380: starting container process caused: exec: "../scripts/start.sh": stat ../scripts/start.sh: no such file or directory: unknown.
What is this about?
I believe this is caused by wrong working directory. Try to change working directory to what used to be after your operation, or do not touch it if possible
refer to this
WORKDIR /opt/nifi/nifi-current

starting container process caused "exec: \"/bin/sh\": stat /bin/sh: no such file or directory":

I am trying to build an docker image on centos 7 from SCRATCH. I have performed following steps :
FROM scratch
RUN rpm -ivh https://address/app.rpm
RUN YUM install tools
...
...
CMD ["rpm","start"]
After executing this , I tried to build this dockerfile with command
"docker build -t testsid -f ./dockerfile ."
Now I see following error :
Sending build context to Docker daemon 3.072kB
Step 1/16 : FROM scratch
--->
Step 2/16 : RUN rpm -ivh https://address/app.rpm
---> Running in d25a0a879d9e
OCI runtime create failed: container_linux.go:349: starting container process caused "exec: \"/bin/sh\": stat /bin/sh: no such file or directory": unknown
Please let me know whether anyone has suggestion regarding this. ?
Any input will be really helpful.
Thank you.
FROM scratch starts from a totally empty image. The only things that will be in the container filesystem at all are files in /dev, /proc, and /etc that Docker automatically provides. When you say rpm, that command doesn't exist. A string-form RUN command gets wrapped in /bin/sh -c ..., but there is no /bin directory.
FROM scratch is a somewhat advanced use of Docker. If you're very comfortable with concepts like statically-linked binaries and the differences between bare-string and JSON-array CMD, you can use it to make an extremely small image. For most typical uses you'll want to at least start from something with some sort of distribution and package manager.
If you need Red Hat's package management tools, the easiest Docker Hub image to start from will be centos:
FROM centos:8 # includes rpm, yum, /bin directory
RUN rpm -ivh https://address/app.rpm
RUN yum install tools
...

Can we use RUN instruction with base image as scratch?

FROM scratch
RUN mkdir hello
This is my Dockerfile, and i am unable to build image for this.
Build command is docker build -t sample .
Below is the output
Sending build context to Docker daemon 2.048kB
Step 1/2 : FROM scratch
--->
Step 2/2 : RUN mkdir hello
---> Running in faafa9f9aa98
OCI runtime create failed: container_linux.go:346: starting container process caused "exec: \"/bin/sh\": stat /bin/sh: no such file or directory": unknown
A scratch image contains nothing, not even /bin/sh or /usr/bin/mkdir.
So you can't RUN anything unless you COPY in into the image first.

OCI runtime create failed: container_linux.go:296 - no such file or directory

End of my Dockerfile:
ENTRYPOINT ["ls /etc"]
Terminal:
...Rest of the building above is fine
Step 8/8 : ENTRYPOINT ["ls /etc"]
---> Using cache
---> ea1f33b8ab22
Successfully built ea1f33b8ab22
Successfully tagged redis:latest
k#Karls ~/dev/docker_redis (master) $ docker run -d -p 6379:6379 --name red redis
71d75058b94f088ef872b08a115bc12cece288b53fe26d67960fe139953ed5c4
docker: Error response from daemon: OCI runtime create failed: container_linux.go:296: starting container process caused "exec: \"ls /etc\": stat ls /etc: no such file or directory": unknown.
For some reason, it won't find the directory /etc. I did a pwd and the current working directory is /. I also did a ls / on the entrypoint and that displayed the /etc directory fine.
OCI runtime create failed: container_linux.go:296
In my experience this is an error with the docker daemon itself, not the container you are trying to run. Try deleting all containers, restarting the daemon. I think we also had to clean up the docker networks.
I appear to be having the same issue. Here is what I am doing.
Dockerfile
FROM gcc:7.2.0
COPY src/ /usr/src/myapp
WORKDIR /usr/src/myapp
RUN set -x gcc -o myapp main.c
CMD ["./myapp"]
Build
$ docker build -t test .
Sending build context to Docker daemon 3.584kB
Step 1/6 : FROM gcc:7.2.0
...
---> 3ec35c7d2396
Successfully built 3ec35c7d2396
Successfully tagged test:latest
SECURITY WARNING: You are building a Docker image from Windows against a
non-Windows Docker host. All files and directories added to build context
will have '-rwxr-xr-x' permissions. It is recommended to double check and
reset permissions for sensitive files and directories.
Run
$ docker run -it test
D:\Docker Toolbox\docker.exe: Error response from daemon: OCI runtime create
failed: container_linux.go:296: starting container process caused "exec:
\"./myapp\": stat ./myapp: no such file or directory": unknown.
Changed CMD to ENTRYPOINT and removed the set -x seemed to resolve the problem. Though we are still unsure what the cause was or if this will also work for you.
Make sure that /etc exists or is created as the main.c wasn't compiling.
Dockerfile
FROM gcc:7.2.0
COPY src/ /usr/src/myapp
WORKDIR /usr/src/myapp
RUN gcc -o myapp main.c
ENTRYPOINT ["./myapp"]
On OSX, I fixed it by clearing the volume data manually. Close docker, and remove everything in ~/Library/Containers/com.docker.docker
I've expirienced the same issue after updating my Windows credentials, try following: Docker settings > Shared Drives > Reset credentials > Select drives again > Apply and re-enter your credentials. This solved the problem for me multiple times
The command you are trying to execute inside the container does not exist. In this case ls /etc does not exist in the image. There's a /bin/ls binary, but not a /bin/"ls /etc" binary, which itself would be invalid since the name of a file on the filesystem cannot include a /, though it can include a space.
Of course what you wanted to run was ls with the argument /etc, and for that, you need to separate each argument if you run with the exec syntax.
ENTRYPOINT ["ls", "/etc"]
Or if you wanted to allow a shell to parse the string, same way as if you were at a bash prompt inside the container running ls /etc on the command line, then switch to the string syntax that runs a shell:
ENTRYPOINT ls /etc

How do I run a Bash script in an Alpine Docker container?

I have a directory containing only two files, Dockerfile and sayhello.sh:
.
├── Dockerfile
└── sayhello.sh
The Dockerfile reads
FROM alpine
COPY sayhello.sh sayhello.sh
CMD ["sayhello.sh"]
and sayhello.sh contains simply
echo hello
The Dockerfile builds successfully:
kurtpeek#Sophiemaries-MacBook-Pro ~/d/s/trybash> docker build --tag trybash .
Sending build context to Docker daemon 3.072 kB
Step 1/3 : FROM alpine
---> 665ffb03bfae
Step 2/3 : COPY sayhello.sh sayhello.sh
---> Using cache
---> fe41f2497715
Step 3/3 : CMD sayhello.sh
---> Using cache
---> dfcc26c78541
Successfully built dfcc26c78541
However, if I try to run it I get an executable file not found in $PATH error:
kurtpeek#Sophiemaries-MacBook-Pro ~/d/s/trybash> docker run trybash
container_linux.go:247: starting container process caused "exec: \"sayhello.sh\": executable file not found in $PATH"
docker: Error response from daemon: oci runtime error: container_linux.go:247: starting container process caused "exec: \"sayhello.sh\": executable file not found in $PATH".
ERRO[0001] error getting events from daemon: net/http: request canceled
What is causing this? I recall running scripts in debian:jessie-based images in a similar manner. So perhaps it is Alpine-specific?
Alpine comes with ash as the default shell instead of bash.
So you can
Have a shebang defining /bin/bash as the first line of your sayhello.sh, so your file sayhello.sh will begin with bin/sh
#!/bin/sh
Install Bash in your Alpine image, as you seem to expect Bash is present, with such a line in your Dockerfile:
RUN apk add --no-cache --upgrade bash
This answer is completely right and works fine.
There is another way. You can run a Bash script in an Alpine-based Docker container.
You need to change CMD like below:
CMD ["sh", "sayhello.sh"]
And this works too.
Remember to grant execution permission for all scripts.
FROM alpine
COPY sayhello.sh /sayhello.sh
RUN chmod +x /sayhello.sh
CMD ["/sayhello.sh"]
By using the CMD, Docker is searching the sayhello.sh file in the PATH, BUT you copied it in / which is not in the PATH.
So use an absolute path to the script you want to execute:
CMD ["/sayhello.sh"]
BTW, as #user2915097 said, be careful that Alpine doesn't have Bash by default in case of your script using it in the shebang.

Resources