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 /
Related
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
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.
# 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 .
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.
I am wondering if there is an identical command for copying a folder to current directory like it did using the old MS-DOS. Let's say my current directory location is:
/var/www/
I have folders and files at:
/home/hope/subfolder/docs/
/home/hope/subfolder/images/
/home/hope/subfolder/.config
/home/hope/subfolder/readme.txt
I know that the following command:
cp -rT /home/hope/subfolder .
will copy all the files (even dot hidden files) and folders within the "subfolder" folder to the current directory, so the result will be:
/var/www/docs/
/var/www/images/
/var/www/.config
/var/www/readme.txt
Looks like the command to that to copy the source folder to the current location is:
cp -rT /home/hope/subfolder ./subfolder
although this is fine, I find it that sometimes I will make mistakes for complicated folder names for the destination, so is there a way to use a command like:
cp -rT /home/hope/subfolder .
or even like this
cp -rT /home/hope/subfolder /var/www/.
to have the following result:
/var/www/subfolder/docs/
/var/www/subfolder/images/
/var/www/subfolder/.config
/var/www/subfolder/readme.txt
Thank you.
Just omit the -T parameter, as that's what prevents the command from working properly:
cp -r /home/hope/subfolder .
The -T parameter treats the target argument as a file, so no copying will be performed at all if that is actually a directory.
A friendly reminder: virtually all Unix commands have a --help command line argument that is worth trying out in case of a trouble :)
For me the main barrier was the /home part. I needed to copy files from a folder in my home that started with the letter 'a' to my current folder, which was not home. So I used:
cp home/tmp/a* ./
the first line worked for me. While I was trying commands like:
cp ~/home/tmp/a* ./
but this didn't work.