vjuranek / docker-build-step-plugin

Other
8 stars 97 forks source link

Cannot COPY or ADD files during create image #4

Open kahnvex opened 9 years ago

kahnvex commented 9 years ago

I am having trouble using the COPY and ADD commands in my Dockerfile, for some reason when I do something like this:

ADD . /container/dir
or 
ADD whatever.txt /container/dir
or
COPY . /container/dir

The only thing it adds/copies is the Dockerfile, and not the rest of the contents of the build context. I've been poking around the source, but I cannot pinpoint what the issue could be.

Caveat: My docker host is running on a different IP, and the jenkins instance is running inside a container on that host, but I'd think the docker REST client should still work in this case.

coryking commented 9 years ago

I am having this issue as well--docker isn't seeing any of the files that are alongside the Dockerfile. It is like docker isn't being ran with the right current directory or something.

For what it is worth, docker is running right along side jenkins.

Any ideas @vjuranek ?

kahnvex commented 9 years ago

Make sure you are using all caps ADD. That was my problem. It's unexpected so I'm keeping this open

coryking commented 9 years ago

Everything is capitalized. If it helps, this builds just fine when you do a docker build from the command line.

FROM dockerfile/java

WORKDIR /app

RUN mkdir -p /var/log/somewhere
RUN chmod 0777 /var/log/somewhere

ADD src/main/resources/afile.p12 /app/afile.p12
ADD the_app /app/the_app

# 8081 is used for monitoring....
EXPOSE 8080 8081

CMD []
ENTRYPOINT ["/app/the_app", "server"]

When run using the plugin, I get this error:

Step 5 : ADD src/main/resources/afile.p12 /app/afile.p12

[Docker] ERROR: {"errorDetail":{"message":"src/main/resources/afile.p12: no such file or directory"},"error":"src/main/resources/afile.p12: no such file or directory"}

The file is right where it should be on the filesystem

coryking commented 9 years ago

A clue might be here: http://blog.mx17.net/2014/02/12/dockerfile-file-directory-error-using-add/

After a good read of the official documentation I learned the conxept of “build context”. When you are building an image, the source directory from which you are operating is the build context, but when you are building passing the Dockerfile from the standard input, there’s no build context!

tgeens commented 8 years ago

The docker docs explain why exactly - from [http://docs.docker.com/engine/reference/builder/#add]:

Note: If you build by passing a Dockerfile through STDIN (docker build - < somefile), there is no build context, so the Dockerfile can only contain a URL based ADD instruction.

But they also continue with a hint for a solution:

You can also pass a compressed archive through STDIN: (docker build - < archive.tar.gz), the Dockerfile at the root of the archive and the rest of the archive will get used at the context of the build.

tgeens commented 8 years ago

It should be feasible to create this archive.tar.gz on the fly.

Side problem: do you really want to stream an archive with the full directory structure ? Edit: is that where .dockerignore could be useful ?

nweiler commented 7 years ago

Any resolution on this issue? I'm still seeing that other files besides the Dockerfile aren't being copied to the remote location and can't be added via COPY or ADD to image.