Search code examples
windowsdockerdockerfile

Creating base image FROM scratch


I installed Docker Desktop version 24.0.7

In Dockerfile I have the following:

# Use a scratch base image for Windows
FROM scratch
# Copy the executable into the container`your text`
COPY hello.cmd /
# Set the default command to run when the container starts
CMD ["hello.cmd"]`

hello.cmd contains:

@echo Hello, World!

Build (docker build -t my-hello .) seems to finish OK, but running the container gives the following error:

PS C:\Windows\Dockdir> docker run -it my-hello
docker: Error response from daemon: failed to create task for container: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: exec: "hello.cmd": executable file not found in $PATH: unknown.

What am I doing wrong? Adding WORKDIR Dockerfile didn't help.

I know adding a parent image to FROM clause solve this, but I want to create an image FROM scratch in Windows.


Solution

  • I am new to docker too, why did you not provide all info you have done before doing:

    docker build -t my-hello .
    

    The steps might be obvious to an experienced docker-user, but ...

    D:\TEMP\temp>dir
     Volume in drive D is HDD
     Volume Serial Number is D46B-804B
    
     Directory of D:\TEMP\temp
    
    25-12-2023  17:40    <DIR>          .
    25-12-2023  16:22    <DIR>          ..
    25-12-2023  16:59               204 Dockerfile
    25-12-2023  17:03                30 hello.cmd
                   2 File(s)            234 bytes
                   2 Dir(s)  95.182.155.776 bytes free
    
    D:\TEMP\temp>docker build -t my-hello .
    Sending build context to Docker daemon  3.072kB
    Step 1/3 : FROM scratch
    Windows does not support FROM scratch
    
    D:\TEMP\temp>