Dockerhub automated build fails, "not a directory" when adding file - dockerhub

I am trying to use docker hub to automatically build something that builds fine locally. It fails saying:
Build process failed: stat /var/lib/docker/aufs/mnt/1be9db483fa6f3de2596b5261e7c450de8df503185e579278396f14ba179c257/bin/run.sh: not a directory
You can view the build itself here:
https://hub.docker.com/r/zbyte64/rethinkdb-tlsproxy/builds/bjclhq33kgwxxvn6nbfsgyh/
run.sh is in the same directory as Dockerfile, it seems the build path on dockerhub is different then where it stores the Dockerfile.
I have tried the following variations:
COPY run.sh /bin
ADD ./run.sh /bin

The COPY command (on Dockerhub's Docker version) expects the target file on the right hand side, not just the target directory. The following command should work for you even on Dockerhub.
COPY run.sh /bin/run.sh

Or if you want to use ADD, include the trailing slash.
ADD ./run.sh /bin/
What is actually happening? From https://docs.docker.com/engine/reference/builder/#add :
ADD src dest
"If dest does not end with a trailing slash, it will be considered a regular file and the contents of src will be written at dest."
Without the trailing slash on /bin, it expects run.sh to be a directory being copied to directory /bin.

I don't know why, but dockerhub wants the first argument of COPY or ADD to be a directory - not a file. I am running Docker 1.9.1 locally and that is not the case. I switched the Dockerfile to copy a resource directory instead of individual files and things started to work.

Related

Dockerfile COPY failed with particular directory name

A normal COPY line in my Dockerfile is preventing the image from being built.
COPY privoxy.config /etc/privoxy/config/
The log says
failed to copy files: failed to create new directory: mkdir /var/lib/docker/overlay2/e6748c046ce142595c7d4fec886898f88abf9a932876b80b436ea5fd24b705a5/merged/etc/privoxy/config: not a directory
Just want to figure out why this peculiar problem happens. I've made sure the dest path is with the trailing slash and tried to change the path name, the problem dissappered when I changed the config in the dest path to conf. I've also presumed it was related to the privoxy.config extension name but after experiment it was not the case.
COPY will create the destination directory in the image if it doesn't already exist. However, if the destination already exists but it's a file (or something else that's not a directory) you can get this error.
You can verify this with a temporary container:
docker run --rm the-base-image \
ls -ld /etc/privoxy/config
If the destination is a file, and you want to COPY that source file to that specific image file, then you can remove the / at the end of the path to cause Docker to overwrite the existing file.
COPY privoxy.config /etc/privoxy/config # <-- no trailing /

Docker ADD giving error "No source files were specified"

Dockerfile is failing on the following line:
ADD ./test-web-app/build/libs/test-web*.war /app/test-web.war
Error Step 8/29 : COPY ./test-web-app/build/libs/test-web*.war
/app/micro-service.war No source files were specified
This is the first time I am working on Docker builds. How do I debug this issue? Is there a way to echo if the host file is existing by a command ?
be sure that the path of the file is accessible where the Dockerfile is. When you run the build, the . folder is where the Dockerfile is. So you directory structure has to be something similar to this:
.
..
Dockerfile
test-web-app (folder)
To be sure that the war file is accessible try to list the file (on your host machine) for example.
$ ls ./test-web-app/build/libs/test-web*.war

Unable to replace files in docker image with ADD or COPY

I am trying to replace some files in a folder in a docker image. I am using the following command inside Dockerfile:
COPY /home/adietz/Work/20_BSP/Jenkins/venvs/linux_selenium/lib/python2.7/site-packages/browsermobproxy /usr/local/lib/python2.7/dist-packages/browsermobproxy
which results in an error
Step 4/12 : COPY /home/adietz/Work/20_BSP/Jenkins/venvs/linux_selenium/lib/python2.7/site-packages/browsermobproxy /usr/local/lib/python2.7/dist-packages/browsermobproxy
lstat home/adietz/Work/20_BSP/Jenkins/venvs/linux_selenium/lib/python2.7/site-packages/browsermobproxy: no such file or directory
Replacing COPY with ADD results in the same error. Also the following command
COPY /home/adietz/Work/20_BSP/Jenkins/venvs/linux_selenium/lib/python2.7/site-packages/browsermobproxy /usr/local/lib/python2.7/dist-packages/
and gives identical(!) error.
Both paths are folders. The folder in the docker image already exists; I just want to replace the files.
What am I doing wrong here...?
It seems you cannot use absolute paths in the COPY command AND you can only copy files which are inside the folder you are running the docker command.
So to copy these files you have to do e.g. the following steps
cp -r /home/adietz/Work/20_BSP/Jenkins/venvs/linux_selenium/lib/python2.7/site-packages/browsermobproxy .
and then add to the Dockerfile:
COPY browsermobproxy/ /usr/local/lib/python2.7/dist-packages/
A symbolic link also does not work...
I had this same issue and realized that COPY or ADD won't work with node_modules that are referenced instead of directly installed into the project. When I switched this it worked for me.

How to copy multiple files in one layer using a Docker file to different locations?

Is it possible to copy multiple files to different locations in a Dockerfile?
I'm looking to go from:
COPY outputs/output/build/.tools /root/.tools
COPY outputs/output/build/configuration /root/configuration
COPY outputs/output/build/database/postgres /root/database/postgres
I have tried the following, but no joy:
COPY ["outputs/output/build/.tools /root/.tools","outputs/output/build/configuration /root/configuration","outputs/output/build/database/postgres /root/database/postgres"]
Not sure if this is even possible.
Create a file .dockerignore in your docker build context directory. Create a soft link (ln) of the root directory you want to copy and exclude the directories you don't want in your .dockerignore.
In your case, you don't need the soft link as the directory is already in the docker build context. Now, add the directories in the .dockerignore file that you don't want eg. if you don't want bin directory you can do that as,
# this is .dockerignore file
outputs/output/build/bin*
Finally in your Dockerfile,
COPY outputs/output/build/ /root/
Details are here.
it looks like you are trying to do bash style [] brace expansion
RUN command uses sh NOT bash
see this SO article discussing it
Bash brace expansion not working on Dockerfile RUN command
or the docker reference
https://docs.docker.com/engine/reference/builder/#/run

How to copy/add files in user's home directory in host to container's home directory?

# Update
I just realized that ADD/COPY command doesn't permit any access
to files or directories outside of current working directory in host.
One more thing is that if you specify an absolute path of file/directory
as a source path after ADD/COPY command, it'll also not be permitted.
Please refer to this and have happy hacking ! :)
=======================================================================
I would like to copy/add files under a user's home directory in host
into the container's home directory for the same user.
First of all, a user can be changed as the user who is building a docker image with Dockerfile on each host. For instance, in my host, I have a user "test". In the other person's host, there will be a user "newbie". In each host, my Dockerfile will be built/used.
The following is my test syntax for copying/adding files.
...
RUN mkdir -p /home/${USER}/.ssh
ADD /home/${USER}/.ssh/id_rsa* /home/${USER}/.ssh/
or COPY /home/${USER}/.ssh/id_rsa* /home/${USER}/.ssh/
...
When I try to build this Docker file, the following error is displayed.
Step 43/44 : ADD /home/user/.ssh/id_rsa* /home/${USER}/.ssh/
No source files were specified
Please kindly guide me to do what I want to do. :)
Thanks.
It has now been two years sice the question has been ask, but I want to cite to official documentation here which states the same as what #Sung-Jin Park already found out.
ADD obeys the following rules:
The path must be inside the context of the build; you cannot ADD
../something /something, because the first step of a docker build is
to send the context directory (and subdirectories) to the docker
daemon.
Dockerfile reference ADD
you can use the following:
WORKDIR /home
COPY ${pwd}/my-file.txt .

Resources