Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can I COPY a file to docker image's directory '/usr/local/bin/'? #1876

Closed
andyzhaozhao opened this issue Jul 31, 2019 · 13 comments
Closed

Comments

@andyzhaozhao
Copy link

In Dockerfile,I can do this by "COPY xxx.sh /usr/local/bin/". How do it in Jib?

@briandealwis
Copy link
Member

See the extraDirectories item (Maven, Gradle).

@andyzhaozhao
Copy link
Author

extraDirectories can‘t solve my problem. @briandealwis .I need copy a file into a folder of docker i mage. I didn't found a way of extraDirectories to solve it. extraDirectories:

<configuration>
  <!-- Copies files from 'src/main/custom-extra-dir' and '/home/user/jib-extras' instead of 'src/main/jib' -->
  <extraDirectories>
    <paths>
      <path>src/main/custom-extra-dir</path>
      <path>/home/user/jib-extras</path>
    </paths>
  </extraDirectories>
</configuration>

But I wan't to do this.
in Dockerfile:

...
COPY  wait-for-it.sh   /usr/local/wait-for-it.sh
...

copy the the file wait-for-it.sh into docker images's /usr/local/wait-for-it.sh.

@chanseokoh
Copy link
Member

@andyzhaozhao you can place the wait-for-it.sh file at <project root>/src/main/jib/usr/local/wait-for-it.sh. No configuration is needed in this case (when using the default extra files directory src/main/jib). Then Jib will put the file at /usr/local/wait-for-it.sh in the image.

@andyzhaozhao
Copy link
Author

@briandealwis @chanseokoh Thank you. But I don't wan't to change my src codes. So high coupling of it. The 'ops' codes invade into the 'dev' codes. I think this‘s not
a good way to copy the wait-for-it.sh file to my src directory. I want separate the Dev and Ops.Are there any other way to solve my problem? May be I need use the Dockerfile directly instead of Jib?

@chanseokoh
Copy link
Member

chanseokoh commented Aug 12, 2019

Then, how about making a custom base image that has wait-for-it.sh pre-installed and have Jib base on it? Or, maybe the other direction: for example, you could run Jib without the script, and a later ops step could put the script using a Dockerfile, if that is the loose coupling you are talking about?

@andyzhaozhao
Copy link
Author

Will Jib Support COPY in the pom.xml now?

@chanseokoh
Copy link
Member

chanseokoh commented Aug 12, 2019

I'd say that is basically what <extraDirectories> does. You can configure the source path (directory) and control the destination at the same time.

@andyzhaozhao
Copy link
Author

@chanseokoh thank you as same. But ,either preparing a docker image which contains the wait-for-it.sh or putting script in other ops step is not a simple way to solve my problem.

@andyzhaozhao
Copy link
Author

How can I control the destination by extraDirectories ? @chanseokoh

@chanseokoh
Copy link
Member

chanseokoh commented Aug 12, 2019

UPDATE: #1581 is fixed, so now you can specify the target path inside an image when copying files with <extraDirectories>.See #1581 (comment) for more details.


For now, you have to layout the file structure as you would want to see it in the image. For example, let's say locally you have /tmp/foo/bar/baz.txt in your laptop. Then if you specify the /tmp directory as <extraDirectories><paths><path>, the baz.txt will be placed under /foo/bar/ in the image. This is how you control the destination.

@ayhanap
Copy link

ayhanap commented Mar 17, 2023

Is there a way to not override the entire destination folder but just copy the files?

Currently below configuration overrides the destination folder. So if existing files in the base image under /lib64 deleted and replaced with src/main/custom-extra-dir/lib64.

<path>
  <from>src/main/custom-extra-dir/lib64</from>
  <into>/lib64</into>
</path>

@chanseokoh
Copy link
Member

@ayhanap if so, it must be that /lib64 is a symlink file.

@ayhanap
Copy link

ayhanap commented Mar 17, 2023

@chanseokoh Yeah seems it is pointing to lib64 -> usr/lib64. Thanks a lot for the clarification.

Can confirm if I use usr/lib64 which is not a symlink but a directory it copies the files without overriding the destination directory.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants