I'm learning Docker and I'm trying to create the most simple and light image as possible. That's what I did.
helloworld
directory:
$ ls
Dockerfile helloworld.c
helloworld.c
#include <stdio.h>
int main() {
printf("Hello world!\n");
return 0;
}
Dockerfile
FROM scratch
COPY helloworld /
CMD ["/helloworld"]
I compiled the .c
file:
$ gcc -o helloworld helloworld.c
$ ./helloworld
Hello world!
Then I created the image:
$ docker build --tag helloworld .
[+] Building 0.2s (5/5) FINISHED
=> [internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 93B 0.0s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> [internal] load build context 0.0s
=> => transferring context: 33B 0.0s
=> CACHED [1/1] COPY helloworld / 0.0s
=> exporting to image 0.0s
=> => exporting layers 0.0s
=> => writing image sha256:c5664c4c93727aae40daca2c1fc0aa13ea2e2c58ba2962fa8d981aa0ec09012e 0.0s
=> => naming to docker.io/library/helloworld
Then when I run the container I get the error exec /helloworld: no such file or directory
:
$ docker run helloworld
exec /helloworld: no such file or directory
What am I doing wrong? Should I compiled the helloworld
in a different mode?