locked
TP4: docker build can add files to image, but docker run can't see the files RRS feed

  • Question

  • I have problems with TP4 adding files or programs to a docker image while 
    docker build. The build itself looks pretty fast and good and the image
    size looks plausible. But running the created container image does not show
    the files.

    I have stripped down my problem to this scenario:

    1. Create a work directory

    mkdir test
    cd test

    2. Create a Dockerfile with following lines

    FROM windowsservercore
    ADD test.txt test.txt
    CMD [ cmd.exe ]

    3. Create a small text file test.txt

    echo test >test.txt

    4. Build the docker image

    docker build -t test .

    Sending build context to Docker daemon 3.072 kB
    Step 1 : FROM windowsservercore
     ---> 6801d964fda5
    Step 2 : ADD test.txt test.txt
     ---> 873e3200f1b1
    Removing intermediate container 50bc97b31bb3
    Step 3 : CMD [ cmd.exe ]
     ---> Running in d736a601c38d
     ---> 1f4782a2cb3c
    Removing intermediate container d736a601c38d
    Successfully built 1f4782a2cb3c

    5. Start a docker container with that image to test if the file can be found

    docker run -it test cmd /c dir test.txt

     Volume in drive C has no label.
     Volume Serial Number is 00B8-29D9

     Directory of C:\Windows\system32

    File Not Found

    Can anybody replicate the problem?

    Is it a problem with the docker.exe?

    Additional info:

    PS C:\Users\vagrant\test> docker version
    Client:
     Version:      1.10.0-dev
     API version:  1.22
     Go version:   go1.5.1
     Git commit:   59a341e
     Built:        Fri Nov 13 17:23:07 UTC 2015
     OS/Arch:      windows/amd64

    Server:
     Version:      1.10.0-dev
     API version:  1.22
     Go version:   go1.5.1
     Git commit:   59a341e
     Built:        Fri Nov 13 17:23:07 UTC 2015
     OS/Arch:      windows/amd64



    Friday, November 20, 2015 11:19 PM

Answers

  • Stefan,

    I think I see the issue...  we start our execution in the c:\windows\system32 working directory by default.  In Step 5 if you tried "docker run -it test cmd /c dir c:\test.txt  I think it would work or if you set the working dir to \.

    However this does pose a question - should our default working dir be root (aka C:\)?  Would love any feedback on this.


    -Taylor

    Saturday, November 21, 2015 12:09 AM
  • There's a few problems you have here.

    First, the ADD needs a location so for example ADD file.txt / would put file.txt into the c:\ directory (you need to use Unix file semantics in a Dockerfile, even on Windows). The destination will be relative to the current WORKDIR which defaults to c:\.

    Second in the exec format, the executable must be in double quotes. This applies to RUN/ENTRYPOINT/CMD. See http://docs.docker.com/engine/reference/builder/#cmd

    Third, echo is not a built in command in Windows such as echo.exe. It's part of the shell. So really you want your CMD to be ["cmd", "/s", "/c"].

    Fourth, the default directory when starting a container if you just run cmd as in your example will be c:\windows\system32 as you see. The file would have been located at c:\. This is because administrative command prompts start in the system directory, but non admin start in the users directory. As you're running as local system inside the container (you can't control that), that's why you see c:\windows\system32.

    Fifth, I'm sure (99%+) that docker from 'Friday the 13th' of November does not have a critical fix merged which breaks the argument escaping of a command in a Dockerfile. Use the version from http://get.docker.com/windows/tp4/docker.exe, or one from master.dockerproject.org.

    Minor point, you don't need -it on your docker run as you're not interactive in the command you're running. So with the modification to the CMD as above, you could just do docker run imagename dir c:\

    (Caveat, I'm not in front of a machine to verify).

    Cheers,
    John. (One of the guys doing the daemon port to Windows...)

    Saturday, November 21, 2015 1:38 AM

All replies

  • Stefan,

    I think I see the issue...  we start our execution in the c:\windows\system32 working directory by default.  In Step 5 if you tried "docker run -it test cmd /c dir c:\test.txt  I think it would work or if you set the working dir to \.

    However this does pose a question - should our default working dir be root (aka C:\)?  Would love any feedback on this.


    -Taylor

    Saturday, November 21, 2015 12:09 AM
  • There's a few problems you have here.

    First, the ADD needs a location so for example ADD file.txt / would put file.txt into the c:\ directory (you need to use Unix file semantics in a Dockerfile, even on Windows). The destination will be relative to the current WORKDIR which defaults to c:\.

    Second in the exec format, the executable must be in double quotes. This applies to RUN/ENTRYPOINT/CMD. See http://docs.docker.com/engine/reference/builder/#cmd

    Third, echo is not a built in command in Windows such as echo.exe. It's part of the shell. So really you want your CMD to be ["cmd", "/s", "/c"].

    Fourth, the default directory when starting a container if you just run cmd as in your example will be c:\windows\system32 as you see. The file would have been located at c:\. This is because administrative command prompts start in the system directory, but non admin start in the users directory. As you're running as local system inside the container (you can't control that), that's why you see c:\windows\system32.

    Fifth, I'm sure (99%+) that docker from 'Friday the 13th' of November does not have a critical fix merged which breaks the argument escaping of a command in a Dockerfile. Use the version from http://get.docker.com/windows/tp4/docker.exe, or one from master.dockerproject.org.

    Minor point, you don't need -it on your docker run as you're not interactive in the command you're running. So with the modification to the CMD as above, you could just do docker run imagename dir c:\

    (Caveat, I'm not in front of a machine to verify).

    Cheers,
    John. (One of the guys doing the daemon port to Windows...)

    Saturday, November 21, 2015 1:38 AM
  • John, thanks. Yes, I've stripped down the example too simple that it could work, sorry for that.

    With a Dockerfile that has a proper workdir like this, it works:

    FROM windowsservercore
    RUN mkdir \work
    WORKDIR /work
    ADD test.txt /work/test.txt
    CMD [ "cmd.exe" ]

    Creating the test.txt file on the host and building the container image:

    echo hello >test.txt

    docker build -t test .

    docker run -it test cmd /c dir

    it shows

     Volume in drive C has no label.
     Volume Serial Number is 00B8-29D9

     Directory of C:\work

    11/21/2015  11:54 AM    <DIR>          .
    11/21/2015  11:54 AM    <DIR>          ..
    11/21/2015  12:01 AM                14 test.txt
                   1 File(s)             14 bytes
                   2 Dir(s)  21,224,919,040 bytes free

    And I also will try the other docker versions, the  http://get.docker.com/windows/tp4/docker.exe is of 20th of November and probably has some more PR's merged in it.

    And just for the records: Another test with my too simple Dockerfile shows that the test.txt has been copied to c:\test.txt.

    Thanks,

    Stefan

    Saturday, November 21, 2015 11:08 AM