I have read http://docs.docker.com/engine/reference/builder/#add however I met a problem. I want to copy the local directory go to docker /user/local/
I tried:
ADD go /usr/local/
and:
ADD /go/ /usr/local/
also:
RUN chmod 0755 /usr/local/go/src/make.bash
However, I see the following error message:
/usr/local/go/src/make.bash: No such file or directory
but the local go directory does contain make.bash.
ADD go /usr/local/
will copy the contents of your local go directory in the /usr/local/ directory of your docker image.
To copy the go directory itself in /usr/local/ use:
ADD go /usr/local/go
or
COPY go /usr/local/go
Indeed ADD go /usr/local/ will add content of go folder and not the folder itself, you can use Thomasleveil solution or if that did not work for some reason you can change WORKDIR to /usr/local/ then add your directory to it like:
WORKDIR /usr/local/
COPY go go/
or
WORKDIR /usr/local/go
COPY go ./
But if you want to add multiple folders, it will be annoying to add them like that, the only solution for now as I see it from my current issue is using COPY . . and exclude all unwanted directories and files in .dockerignore, let's say I got folders and files:
- src
- tmp
- dist
- assets
- go
- justforfun
- node_modules
- scripts
- .dockerignore
- Dockerfile
- headache.lock
- package.json
and I want to add src assets package.json justforfun go so:
in Dockerfile:
FROM galaxy:latest
WORKDIR /usr/local/
COPY . .
in .dockerignore file:
node_modules
headache.lock
tmp
dist
In this way, you ignore node_modules headache.lock tmp dist so they will not be added!
Or for more fun (or you like to confuse more people make them suffer as well :P) can be:
*
!src
!assets
!go
!justforfun
!scripts
!package.json
In this way you ignore everything, but exclude what you want to be copied or added only from the "ignore list".
It is a late answer but adding more ways to do the same covers even more cases.
You can use COPY. You need to specify the directory explicitly. It won't be created by itself
COPY go /usr/local/go
Reference: Docker CP reference
As the official docs state:
The directory itself is not copied, just its contents.
The trick is to concat in the <dest> path also the folder name, like this:
COPY src ./src
Even if ./src does not exist in the container yet, the command COPY internally creates it and copies the content of src into the new folder (which is ./src).
This can help if you want to add all files to a specified location
#ADD XML SUITE files
ADD src/test/resources/xmls/* /usr/share/tag/
Related
I have a folder tmpdata with slightly different permissions at the top level of my project, which is used by a separate container to be able to restart with data.
I list this tmpdata/ folder in my .dockerignore file because I don't want it to be part of the build for the main app.
In my Dockerfile, I do have a COPY . . directive though. I thought it would copy everything except whatever's listed in .dockerignore, but when I try to build, I get:
failed to solve with frontend dockerfile.v0: failed to read dockerfile: error from sender: open tmpdata: permission denied
My question is, why isn't the .dockerignore file preventing the build process from even trying to touch this folder? Is there a way to have the COPY command respect (ignore) entries in the .dockerignore file?
UPDATE even after refactoring the dockerfile to use selective COPY commands that only copy needed files, docker build still fails, complaining about the same tmpdata folder.
UPDATE 2 my docker ignore file:
.dockerignore
docker-compose.yml
.env
.env.*
.git
test/
src/test/
**/*.spec.*
**/*.test.*
**/node_modules/
npm-debug.log
.gitignore
.cache
.DS_Store
.thumbsdb
dist/
_unused/
.vscode/
**/*.md
**/.git
tmpdata/
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.
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
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.
My directory Structure as follows
Dockerfile downloads
I want to add downloads to /tmp
ADD downloads /tmp/
COPY down* /tmp
ADD ./downloads /tmp
Nothings works. It copies the contents of downloads into tmp. I want to copy the downloads floder. Any idea?
ADD . tmp/
copies Dockerfile also. i dont want to copy Dockerfile into tmp/
I believe that you need:
COPY downloads/ /tmp/downloads/
That will copy the contents of the downloads directory into a directory called /tmp/downloads/ in the image.
Note: The directory itself is not copied, just its contents
From the dockerfile reference about COPY and ADD, it says Note: The directory itself is not copied, just its contents., so you have to specify a dest directory explicitly.
RE: https://docs.docker.com/engine/reference/builder/#copy
e.g.
Copy the content of the src directory to /some_dir/dest_dir directory.
COPY ./src /some_dir/dest_dir/
You can use:
RUN mkdir /path/to/your/new/folder/
COPY /host/folder/* /path/to/your/new/folder/
I could not find a way to do it directly with only one COPY call though.
The best for me was:
COPY . /tmp/
With following .dockerignore file in root
Dockerfile
.dockerignore
# Other files you don't want to copy
This solution is good if you have many folders and files that you need in container and not so many files that you don't need.
Otherwise user2807690' solution is better.
First tar the directory you want to ADD as a single archive file:
tar -zcf download.tar.gz download
Then ADD the archive file in Dockerfile:
ADD download.tar.gz tmp/
If you folder does not end with a /it is considered a file, so you should something like write ADD /abc/ def/ if you want to copy a folder.