Skip to content

Windows docker daemon with different behavior for ONBUILD COPY + WORKDIR #15817

@StefanScherer

Description

@StefanScherer

Description of problem:
I'm trying to port the official Linux iojs:onbuild Dockerfile to Windows and found a different behavior at the ONBUILD COPY keyword in combination with the WORKDIR.

docker version:

Client:
 Version:      1.9.0-dev
 API version:  1.21
 Go version:   go1.4.2
 Git commit:   4376380
 Built:        Wed Aug 19 14:59:24 UTC 2015
 OS/Arch:      windows/amd64

Server:
 Version:      1.9.0-dev
 API version:  1.21
 Go version:   go1.4.2
 Git commit:   4376380
 Built:        Wed Aug 19 14:59:24 UTC 2015
 OS/Arch:      windows/amd64

docker info:

Containers: 37
Images: 89
Storage Driver: windowsfilter
 Windows:
Execution Driver: Windows 1854 1.9.0-dev 4376380
Logging Driver: json-file
Kernel Version: 10.0 10514 (10514.0.amd64fre.th2_release.150808-1529)
Operating System: Windows Server 2016 Technical Preview 3
CPUs: 2
Total Memory: 4 GiB
Name: VAGRANT-2016
ID: 3A6C:S32I:LEC6:YQJB:7PIZ:OK6F:5DEX:X4EI:4SQV:U6MJ:FOTF:W2KN
Debug mode (server): true
File Descriptors: -1
Goroutines: 14
System Time: 2015-08-22T12:59:06.9061205-07:00
EventsListeners: 0
Init SHA1:
Init Path: C:\Windows\System32\docker.exe
Docker Root Dir: C:\ProgramData\docker

uname -a:

MSYS_NT-10.0 vagrant-2016 2.1.0(0.288/5/3) 2015-06-28 18:57 x86_64 Msys

Environment details (AWS, VirtualBox, physical, etc.):
Windows 2016 TP3 running in VMware Fusion 7.1.2 on a Mac OSX 10.10.4

How reproducible:

Steps to Reproduce:

  1. Clone a sample repo with the Windows version of iojs 3.2.0
  2. Build the iojs:lastest and iojs:3.2.0 Docker images
  3. Build the iojs:onbuild Docker image and try to use it.

Here are the exact steps to reproduce it:

git clone https://github.com/StefanScherer/dockerfiles-windows
cd dockerfiles-windows\iojs\3.2.0
docker build -t iojs .
docker tag iojs:latest iojs:3.2.0
cd onbuild
docker build -t iojs:onbuild -f Dockerfile.workdir .
cd testapp
docker build -t testapp .

The Dockerfile.workdir looks very similar to the official Linux iojs:onbuild Dockerfile:

FROM iojs:3.2.0

RUN mkdir \app
WORKDIR /app

ONBUILD COPY package.json /app/
ONBUILD RUN npm install
ONBUILD COPY . /app

CMD [ "npm.cmd", "start" ]

Actual Results:
Building the testapp Docker image results in an error. It seems that the ONBUILD COPY package.json /app/ does not copy the file into the C:\app directory.

npm ERR! package.json ENOENT: no such file or directory, open 'C:\app\package.json'

Expected Results:
The fie package.json should be copied to C:\app\package.json.

Additional info:

So I tried to use a file name as a target inside the container. The following steps reproduce my next workaround:

cd ..
docker build -t iojs:onbuild -f Dockerfile.workdir2 .
cd testapp
docker build -t testapp .

This Dockerfile.workdir2 looks like this:

FROM iojs:3.2.0

RUN mkdir \app
WORKDIR /app

ONBUILD COPY package.json package.json
ONBUILD RUN npm install
ONBUILD COPY . /app

CMD [ "npm.cmd", "start" ]

And now has this line ONBUILD COPY package.json package.json which works as the testapp Docker image can be built.

But running the container with docker run -it testapp shows another error that the file C:\app\index.js could not be found.

I have inspected the container with a cmd shell and have seen that the directory from the host is copied into a sub directory app:

PS C:\Users\vagrant\dockerfiles-windows\iojs\3.2\onbuild\testapp> docker run -it testapp cmd /c dir
 Volume in drive C has no label.
 Volume Serial Number is 0896-CC16

 Directory of C:\app

08/25/2015  06:25 AM    <DIR>          .
08/25/2015  06:25 AM    <DIR>          ..
08/25/2015  06:25 AM    <DIR>          app
08/25/2015  06:24 AM               337 package.json
               1 File(s)            337 bytes
               3 Dir(s)  21,273,026,560 bytes free

So I tried another workaround with these steps:

cd ..
docker build -t iojs:onbuild -f Dockerfile.workdir3 .
cd testapp
docker build -t testapp .

The Dockerfile.workdir3 looks like this:

FROM iojs:3.2.0

RUN mkdir \app
WORKDIR /app

ONBUILD COPY package.json package.json
ONBUILD RUN npm install
ONBUILD COPY . .

CMD [ "npm.cmd", "start" ]

With the line ONBUILD COPY . . which seems to make it work on Windows.
Running the testapp with docker run -it testapp works.

There is a different behavior between the Linux version and the Windows version. Perhaps it is possible to change the behavior so that the Windows version and the Linux version work the same. This would be easier to port other Dockerfiles to Windows.

PS: I also tried this line ONBUILD COPY package.json . but this seems to break the workdir completely.

/cc @jhowardmsft @swernli

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions