Skip to content

Windows: Fix COPY file . after WORKDIR#27884

Merged
vdemeester merged 1 commit intomoby:masterfrom
microsoft:jjh/copyfiletodot
Oct 31, 2016
Merged

Windows: Fix COPY file . after WORKDIR#27884
vdemeester merged 1 commit intomoby:masterfrom
microsoft:jjh/copyfiletodot

Conversation

@lowenna
Copy link
Copy Markdown
Member

@lowenna lowenna commented Oct 30, 2016

Signed-off-by: John Howard [email protected]

Fixes #27545. @duglin @thaJeztah @friism

This fixes the last of the problems reported in the above issue, specifically on Windows where COPY somefile . after a WORKDIR statement where the workdir does not previously exist in the image, copied the contents of somefile to a filename of the WORKDIR, rather than a file in the folder of the WORKDIR. This change makes the builder on Windows consistent with Linux. Test case added too.

(Another fix for the overall issue from @duglin at #27873)

@MichaelSimons @StefanScherer FYI

@lowenna
Copy link
Copy Markdown
Member Author

lowenna commented Oct 30, 2016

cc @johnstep

@StefanScherer
Copy link
Copy Markdown
Contributor

That's great to have the same experience on both platforms. Seems to have an issue with TestBuildWindowsAddCopyPathProcessing.

@lowenna
Copy link
Copy Markdown
Member Author

lowenna commented Oct 30, 2016

Fixed.

@lowenna lowenna added this to the 1.13.0 milestone Oct 30, 2016
func (s *DockerSuite) TestBuildWindowsAddCopyPathProcessing(c *check.C) {
testRequires(c, DaemonIsWindows)
name := "testbuildwindowsaddcopypathprocessing"
// TODO Windows (@jhowardmsft). Needs a follow-up PR to 22181 to
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this To Done? Somewhere else?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still todo. Nothing to do with this PR.

Copy link
Copy Markdown
Member

@cpuguy83 cpuguy83 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Copy Markdown
Member

@vdemeester vdemeester left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🐸

@vdemeester vdemeester merged commit a0629ea into moby:master Oct 31, 2016
@lowenna lowenna deleted the jjh/copyfiletodot branch October 31, 2016 16:58
@johnstep
Copy link
Copy Markdown
Member

I applied the patch and ran a test that works on Linux (changing FROM, of course):

FROM microsoft/nanoserver
WORKDIR x
COPY Dockerfile .
COPY . .

With this patch, building still fails on Windows but with a different error:

Cannot mkdir: C:\x is not a directory

Before this patch, the error was:

mkdir \\?\Volume{<guid>}\x: The system cannot find the path specified.

@lowenna
Copy link
Copy Markdown
Member Author

lowenna commented Oct 31, 2016

x isn't a directory. Use WORKDIR c:\x

@thaJeztah
Copy link
Copy Markdown
Member

isn't WORKDIR relative to the current location? (i.e. relative to C:\ if that's the current path)

@thaJeztah
Copy link
Copy Markdown
Member

(#3937, #4691)

@lowenna
Copy link
Copy Markdown
Member Author

lowenna commented Oct 31, 2016

PS E:\docker\build\27545> type .\Dockerfile
# escape=`

FROM nanoserver
WORKDIR c:\app
COPY project.json .
COPY . .
PS E:\docker\build\27545> docker build --no-cache .
Sending build context to Docker daemon 4.096 kB
Step 1/4 : FROM nanoserver
 ---> 22738ff49c6d
Step 2/4 : WORKDIR c:\app
 ---> Running in ca6f39443a60
 ---> 6f59f9c15693
Removing intermediate container ca6f39443a60
Step 3/4 : COPY project.json .
 ---> 5c7225b4083f
Removing intermediate container c441b1b1e8fe
Step 4/4 : COPY . .
 ---> 9b9dfa6fcd22
Removing intermediate container 74747f9e78dd
Successfully built 9b9dfa6fcd22
PS E:\docker\build\27545> docker run --rm 5c7 cmd /s /c dir c:\
 Volume in drive C has no label.
 Volume Serial Number is 7E6D-E0F7

 Directory of c:\

10/31/2016  10:55 AM    <DIR>          app
10/05/2016  05:04 PM             1,894 License.txt
10/05/2016  02:22 PM    <DIR>          Program Files
10/05/2016  02:14 PM    <DIR>          Program Files (x86)
10/31/2016  10:56 AM    <DIR>          Users
10/31/2016  10:56 AM    <DIR>          Windows
               1 File(s)          1,894 bytes
               5 Dir(s)  21,258,801,152 bytes free
PS E:\docker\build\27545> docker run --rm 5c7 cmd /s /c dir c:\app
 Volume in drive C has no label.
 Volume Serial Number is 7E6D-E0F7

 Directory of c:\app

10/31/2016  10:55 AM    <DIR>          .
10/31/2016  10:55 AM    <DIR>          ..
10/28/2016  09:04 AM                14 project.json
               1 File(s)             14 bytes
               2 Dir(s)  21,262,458,880 bytes free
PS E:\docker\build\27545> docker run --rm 9b9 cmd /s /c dir c:\app
 Volume in drive C has no label.
 Volume Serial Number is 7E6D-E0F7

 Directory of c:\app

10/31/2016  10:55 AM    <DIR>          .
10/31/2016  10:55 AM    <DIR>          ..
10/31/2016  10:53 AM                76 Dockerfile
10/28/2016  09:04 AM                14 project.json
10/28/2016  09:04 AM                14 somefile
               3 File(s)            104 bytes
               2 Dir(s)  21,259,091,968 bytes free
PS E:\docker\build\27545> dir


    Directory: E:\docker\build\27545


Mode                LastWriteTime         Length Name
----                -------------         ------ ----
-a----       10/31/2016  10:53 AM             76 Dockerfile
-a----       10/28/2016   9:04 AM             14 project.json
-a----       10/28/2016   9:04 AM             14 somefile


PS E:\docker\build\27545>

@lowenna
Copy link
Copy Markdown
Member Author

lowenna commented Oct 31, 2016

Good point, yes, it can be relative. But it's working for me on master which contains this patch:

PS E:\docker\build\27545> docker build --no-cache .
Sending build context to Docker daemon 4.096 kB
Step 1/3 : FROM nanoserver
 ---> 22738ff49c6d
Step 2/3 : WORKDIR app
 ---> Running in e64f41b44c12
 ---> 87d35195ee95
Removing intermediate container e64f41b44c12
Step 3/3 : COPY project.json .
 ---> d922038bdfe9
Removing intermediate container c7a5148e9468
Successfully built d922038bdfe9
PS E:\docker\build\27545> docker run --rm d922 cmd /s /c dir c:\
 Volume in drive C has no label.
 Volume Serial Number is 7E6D-E0F7

 Directory of c:\

10/31/2016  10:57 AM    <DIR>          app
10/05/2016  05:04 PM             1,894 License.txt
10/05/2016  02:22 PM    <DIR>          Program Files
10/05/2016  02:14 PM    <DIR>          Program Files (x86)
10/31/2016  10:57 AM    <DIR>          Users
10/31/2016  10:57 AM    <DIR>          Windows
               1 File(s)          1,894 bytes
               5 Dir(s)  21,259,096,064 bytes free
PS E:\docker\build\27545> docker run --rm d922 cmd /s /c dir c:\app
 Volume in drive C has no label.
 Volume Serial Number is 7E6D-E0F7

 Directory of c:\app

10/31/2016  10:57 AM    <DIR>          .
10/31/2016  10:57 AM    <DIR>          ..
10/28/2016  09:04 AM                14 project.json
               1 File(s)             14 bytes
               2 Dir(s)  21,259,087,872 bytes free
PS E:\docker\build\27545>
PS E:\docker\build\27545> docker version
Client:
 Version:      1.13.0-dev
 API version:  1.25
 Go version:   go1.7.1
 Git commit:   a0629ea-jhoward-JHOWARD-Z420-Dynamic
 Built:        Mon Oct 31 17:54:28 UTC 2016
 OS/Arch:      windows/amd64

Server:
 Version:      1.13.0-dev
 API version:  1.25
 Go version:   go1.7.1
 Git commit:   a0629ea-jhoward-JHOWARD-Z420-Dynamic
 Built:        Mon Oct 31 17:54:28 UTC 2016
 OS/Arch:      windows/amd64
 Experimental: false

@lowenna
Copy link
Copy Markdown
Member Author

lowenna commented Oct 31, 2016

a0629ea

@johnstep
Copy link
Copy Markdown
Member

johnstep commented Oct 31, 2016

It works if I add the backtick escape directive:

# escape=`

FROM microsoft/nanoserver
WORKDIR x
COPY Dockerfile .
COPY . .

@johnstep
Copy link
Copy Markdown
Member

@jhowardmsft Has there been discussion on changing the default escape character for Windows? Unfortunately, without versioning, I guess that would break many existing Dockerfiles.

@lowenna
Copy link
Copy Markdown
Member Author

lowenna commented Oct 31, 2016

Yes, discussed significantly in the PR to introduce it. There were many reasons to keep the default as \ on Windows and Linux.

@lowenna
Copy link
Copy Markdown
Member Author

lowenna commented Oct 31, 2016

@johnstep Works for me (as it should do here as there's no / \ ambiguity in this Dockerfile) regardless of the parser directive. Here's without (again running master):

PS E:\docker\build\27545> type dockerfile
FROM nanoserver
WORKDIR app
COPY project.json .
COPY . .
PS E:\docker\build\27545> docker build --no-cache .
Sending build context to Docker daemon 4.096 kB
Step 1/4 : FROM nanoserver
 ---> 22738ff49c6d
Step 2/4 : WORKDIR app
 ---> Running in d660dbb89d79
 ---> 7e798a746f69
Removing intermediate container d660dbb89d79
Step 3/4 : COPY project.json .
 ---> 02656319e083
Removing intermediate container 463f8466e7c9
Step 4/4 : COPY . .
 ---> ae581ab31c0e
Removing intermediate container ea97d4e8f5e1
Successfully built ae581ab31c0e
PS E:\docker\build\27545> docker run --rm 026 cmd /s /c dir c:\app
 Volume in drive C has no label.
 Volume Serial Number is 7E6D-E0F7

 Directory of c:\app

10/31/2016  02:09 PM    <DIR>          .
10/31/2016  02:09 PM    <DIR>          ..
10/28/2016  09:04 AM                14 project.json
               1 File(s)             14 bytes
               2 Dir(s)  21,262,458,880 bytes free
PS E:\docker\build\27545> docker run --rm ae58 cmd /s /c dir c:\app
 Volume in drive C has no label.
 Volume Serial Number is 7E6D-E0F7

 Directory of c:\app

10/31/2016  02:09 PM    <DIR>          .
10/31/2016  02:09 PM    <DIR>          ..
10/31/2016  02:06 PM                59 Dockerfile
10/28/2016  09:04 AM                14 project.json
10/28/2016  09:04 AM                14 somefile
               3 File(s)             87 bytes
               2 Dir(s)  21,259,100,160 bytes free
PS E:\docker\build\27545> dir


    Directory: E:\docker\build\27545


Mode                LastWriteTime         Length Name
----                -------------         ------ ----
-a----       10/31/2016   2:06 PM             59 Dockerfile
-a----       10/28/2016   9:04 AM             14 project.json
-a----       10/28/2016   9:04 AM             14 somefile


PS E:\docker\build\27545>

@johnstep
Copy link
Copy Markdown
Member

It worked fine when I rebuilt with --no-cache; no issues here. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Inconsistent Dockerfile behavior between Windows Containers and Linux

8 participants