-1

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

yuyang
  • 1,511
  • 2
  • 15
  • 40
  • shall I run `docker run --rm hello.sh` ? with that I got ` Unable to find image 'hello.sh:latest' locally...` – yuyang Jul 19 '19 at 19:25

1 Answers1

1

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/

Nathan Lynch
  • 455
  • 3
  • 11
  • 1
    If you're new to Docker, you don't want `FROM scratch`: it is kind of an advanced topic. Most Docker images are built on an Ubuntu, Debian, or Alpine base and I'd recommend starting with one of those images. – David Maze Jul 19 '19 at 20:22