Docker create base image - docker

I am trying to create a docker base image from scratch. The Dockerfile is simple:
FROM scratch
COPY data_folder /opt/data_folder/
CMD ["/opt/data_folder/"]
However, at the final Dockerfile instruction when the default command is run the process exits and says that "oci runtime error: exec: "/opt/data_folder/": permission denied".
Why is this happening since the docker docs specify that this is how you create a base image.
Note: I am using docker on windows native.
Note: The Dockerfile is run from docker-compose up.

You are trying to "execute" a folder /opt/data_folder/
The docker doc suggest executing a command (the executable hello)
FROM scratch
ADD hello /
CMD ["/hello"]

Related

standard_init_linux.go:219: exec user process caused: no such file or directory on Raspbian

Problem: I am attempting to create and run a Docker container of an Edge Service on a Raspberry Pi using 64 bit Raspbian. Due to other limitations, I am attempting to containerize the program (in Golang) by containerizing the build executable file, rather than building the .go in the Dockerfile.
My Dockerfile looks like this
FROM golang:alpine
WORKDIR /build
ADD server .
EXPOSE 50051
CMD ["./server"]
Running the built executable on it's own works correctly, and when creating the Docker Image using the command "sudo docker build -t server:v7 .", the Docker Daemon gives no errors, with the finished image being displayed on the list of Docker Images as if it were correctly working. However, when I try to run the Image, I receive the error "standard_init_linux.go:219: exec user process caused: no such file or directory", rather than the file running.
Some additional notes as per the comments: All of the programs were written in Ubuntu, they were built to an executable on Raspberry Pi, and the Dockerfile was also written on the the Raspberry Pi. When using the command "sudo docker run -it -d : sh", the image will run, and when using the command "sudo docker exec -it sh", terminal will enter the shell. Attempts to run the program from within the shell similarly fail, yielding the error "sh: error not found"
ldd yields the following results:
/lib/ld-linux-aarch64.so.1 (0x7f8731f000)
libpthread.so.0 => /lib/ld-linux-aarch64.so.1 (0x7f8731f000)
libc.so.6 => /lib/ld-linux-aarch64.so.1 (0x7f8731f000)
And there seems to be no problem with Alpine or with $PATH
Do you build on Raspberry or a different machine? If you build on PC, you need to set the build target architecture to match the Raspberry.
The image "golang:alpine" is available for Raspberry, so this should not be the problem.
The error "user process caused: no such file or directory" is then probably related to the file you are trying to execute.
Make sure the file exists in the directory
Make sure the file is executable
Maybe change the CMD to "ls -la" to see in the docker logs if the file is there and which attributes it has.

Docker build error :: exec: \"/bin/sh\": stat /bin/sh: no such file or directory [duplicate]

This question already has an answer here:
Starting container process caused "exec: \"/bin/sh\": stat /bin/sh: no such file or directory": unknown
(1 answer)
Closed 1 year ago.
I am very new to Docker. I figured out on internet on how to build a dockerfile and then create an image.
This is how my docker file looks like:
FROM scratch
ADD abc.py .
RUN pip3 install requests json HTTPBasicAuth
CMD [ "python3", "./abc.py"]
I am using scratch (base image) as I am on a Linux server where we are not allowed to connect to the outside world.
The thing is I am getting the below error when i try to run Docker build command i.e.
docker build -t testimage .
OCI runtime create failed: container_linux.go:345: starting container process caused "exec: "/bin/sh": stat /bin/sh: no such file or directory": unknown
Can anyone explain why is this and what would be the solution. I got some idea about the problem but couldn't identify the solution.
The scratch base is only meant to be used when creating other base images. It contains nothing, not even a shell like bash. If you want to run a python script in a Docker image, I would suggest using a Python base image. For example, you could use python:3.8-slim, which is based on Debian Linux.
FROM python:3.8-slim
COPY abc.py .
RUN pip3 install --no-cache-dir requests
CMD ["python3", "./abc.py"]
I made some changes to your Dockerfile.
Changed ADD to COPY, because the docker documentation says to prefer COPY.
Added --no-cache-dir to pip install to prevent downloads from being cached. This reduces the size of the Docker image.
Removed some packages from pip install because I don't think they exist...
If you cannot pull this base image on your server, then you can try building the image elsewhere and pushing it to your server. If you can build the image somewhere else, then you can use docker export to export it to a tar file. Then you can upload it to your server, and use docker import to convert it to a Docker image.

Combining multiple docker images with multistage build not working

I would like to create a Docker container image that has FFMPEG and NodeJs installed. I am trying a multistage build Dockerfile as follows using the jrottenberg/ffmpeg and node:12 Docker images:
FROM jrottenberg/ffmpeg AS base
FROM node:12 as patch
ENTRYPOINT [ "node", "--version" ]
This container displays the node version correctly as v12.20.2 (as expected). However, if I change the ENTRYPOINT to ffmpeg, I get an error. The modified Dockerfile is as follows:
FROM jrottenberg/ffmpeg AS base
FROM node:12 as patch
ENTRYPOINT [ "ffmpeg", "-version" ]
The error is:
docker: Error response from daemon: OCI runtime create failed:
container_linux.go:370: starting container process caused: exec:
"ffmpeg": executable file not found in $PATH: unknown.
I intend to use a NodeJS program that would spawn FFMPEG as a child process within the container. How do I get this to work?
I have also tried using RUN apt-get install nodejs instruction in the Dockerfile instead of the FROM node:12. That also does not work.
Update:
Incorporating feedback from #David Maze, the following dockerfile accomplished my original goal of NodeJs + FFMPEG on the image.
FROM node:alpine
RUN apk add ffmpeg
COPY ./app.js .
ENTRYPOINT node app.js
Although it is doesn't use a multistage build as I originally intended, it accomplished the purpose. The image size was also much smaller.

"docker run --rm hello" run into "failed: No such file or directory" error

I am new to docker, and follows the instructions at https://docs.docker.com/develop/develop-images/baseimages/ to create a docker image and tried to run:
My docker file is as follows:
FROM scratch
ADD hello.sh /
CMD ["/hello.sh"]
The hello.sh file is as follows. I have applied dos2unix to hello.sh to ensure the right encoding:
#!/bin/sh
echo "this is a test"
I followed the instruction in the doc to run the following command to build an image:
docker build --tag hello .
Then when I ran docker run --rm hello I got the following error:
[FATAL tini (8)] exec /hello.sh failed: No such file or directory
Have searched online and tried solutions from various posts. But none of them worked. Any insights on where I did wrong?
related non-helpful threads:
1. https://forums.docker.com/t/standard-init-linux-go-175-exec-user-process-caused-no-such-file/20025/4
Building an image from 'scratch' means your resulting container is just an empty filesystem. Especially being new to Docker, you should build from a small image like 'alpine' instead of 'scratch' then run your script using sh.
If you are set on building from scratch you will need to compile your own binary then add it as the ENTRYPOINT or CMD of the image Install Bash on scratch Docker image
docker documentation example on building from scratch https://docs.docker.com/develop/develop-images/baseimages/

Cannot start docker container from scratch

Nowadays I am trying to learn about the Docker but still have some ideas not clear;
I have tried to run an image that I just created, here is the directory;
hello (directory) :
Dockerfile
start.sh
And the Dockerfile :
FROM scratch
ADD start.sh /var/
CMD ["/var/start.sh"]
start.sh :
#!/bin/bash
echo "hello world"
I have tagged as using :
docker build -t mozer/hello .
Once I run the command;
docker run mozer/hello
no such file or directory
Error response from daemon: Cannot start container f22019aabc81f29fe17e849a2c040902ccadefe6cb8a8fe2612c83fe8eda40ea: [8] System error: no such file or directory
and once I run the command:
docker run mozer/hello /bin/sh -c
exec: "/bin/sh": stat /bin/sh: no such file or directory
Error response from daemon: Cannot start container 3b54584092e70b639671aca66122a0b1f6b1e4327cb2471a8792c3b2337b0bcc: [8] System error: exec: "/bin/sh": stat /bin/sh: no such file or directory
Can you please give me some ideas to find the solution ?
P.S. : I am working on a machine which is not connected to internet !
FROM scratch is a completely empty filesystem. You have no installed libraries, and no shell (like /bin/sh) included in there. To use this as your base, you'd need a statically linked binary, or you'll need to install all of the normal tools that are included with a linux distribution.
The latter is what is prepackaged in the various busybox, debian, ubuntu, centos, etc images on the docker hub. The fast way to make your image work with a minimal base image is to change the from to FROM busybox and change your /bin/bash to /bin/sh.
Scratch image is an empty file system, there is not /bin/sh inside it.
Look at Creating a simple base image using scratch
You can use Docker’s reserved, minimal image, scratch, as a starting
point for building containers. Using the scratch “image” signals to
the build process that you want the next command in the Dockerfile to
be the first filesystem layer in your image.
You can add an executable compiled program and run it.

Resources