Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker: standard_init_linux.go:211: exec user process caused "no such file or directory"

I am trying to create a base image following the instructions given in official docker webpage(https://docs.docker.com/samples/library/scratch/)

    docker --version
    Docker version 18.09.6, build 481bc77

    OS Details:
    NAME="Ubuntu"
    VERSION="18.04.2 LTS (Bionic Beaver)"

DockerFile:

    FROM scratch
    COPY hello /
    CMD ["/hello"]

hello.c

    #include <stdio.h>
        int main()
        {
           // printf() displays the string inside quotation
           printf("Hello, World!");
           return 0;
        }

I am able to compile the C program and execute locally

I am able to build the image using the dockerfile but when I try to run the container, I get the below error:

    # docker run -i hello
        standard_init_linux.go:211: exec user process caused "no such file or directory" 
    #

I expect the container to run successfully and print "Hello World" on console. most of the answers provided are asking to change EOL which is not applicable as we are already on Linux and not trying to run script.

like image 357
Chaitra Avatar asked Jul 01 '19 08:07

Chaitra


People also ask

What is the difference between entrypoint and CMD in Docker?

Differences between CMD & ENTRYPOINT CMD commands are ignored by Daemon when there are parameters stated within the docker run command while ENTRYPOINT instructions are not ignored but instead are appended as command line parameters by treating those as arguments of the command.

What is docker from scratch?

FROM scratch As of Docker 1.5. 0 (specifically, docker/docker#8827 ), FROM scratch is a no-op in the Dockerfile , and will not create an extra layer in your image (so a previously 2-layer image will be a 1-layer image instead).


1 Answers

I guess you get this error because you built out a dynamic linked binary like next:

$ gcc -o hello hello.c
$ ldd hello
    linux-vdso.so.1 (0x00007ffe3b1ec000)
    libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f7fe1fc7000)
    /lib64/ld-linux-x86-64.so.2 (0x00007f7fe25ba000)

The scratch is really basic which do not have so many so for your binary to dynamic link. So, you need to build out a static link binary, like:

$ gcc -o hello -static hello.c
$ ldd hello
    not a dynamic executable

Then, it will be work like next:

$ docker build -t hello .
Sending build context to Docker daemon  848.4kB
Step 1/3 : FROM scratch
 --->
Step 2/3 : COPY hello /
 ---> 9d594b34f774
Step 3/3 : CMD ["/hello"]
 ---> Using cache
 ---> 2f1bad3099d3
Successfully built 2f1bad3099d3
Successfully tagged hello:latest
$ docker run -i hello
Hello, World!

And, if you do not use scratch image which have more .so in the system, then you no need to build out static binary.

like image 197
atline Avatar answered Sep 21 '22 22:09

atline