Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Dockerfile Copy Optional

rsalazari April 21, 2023

In my pipeline I am using service docker. I am trying to Copy a file if it exists, but the engine version , Copy needs at least one file to exist otherwise it fails. I have tried with global expressions, resource/*.txt, resource/*.tx[t] resource/*.?xt. it doesn't work but in docker desktop it works normal to date. but in my pipeline the same instruction returns this error no error is returned: no source files were specified

1 answer

1 accepted

1 vote
Answer accepted
Theodora Boudale
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
April 24, 2023

Hi @rsalazari and welcome to the community.

If the resource/ directory contains only text files (when it's not empty) and you want to copy all of them, you can try the following command instead

COPY resource/ /path-to-destination-dir/

I have tested this in Pipelines and the command doesn't fail if the resource/ directory is empty.

If the resource/ directory may contain files other than .txt ones that you don't want to copy, I would suggest copying the txt files first in a separate directory before you build the Docker image, so you can then use a COPY command similar to what I have shared.

You mentioned that locally you haven't had any issues. Could you perhaps let me know the output of docker version on this machine, and the OS + version of the machine?

Kind regards,
Theodora

rsalazari April 26, 2023

Thank you very much for the answer in that in my resources folder there are more than one sensitive file and I do not want to copy all of them, only one specific one, of course, as long as the file exists. This is because the idea is to make a dockerfile Generic - my projects contain the same instructions with the differential that some do not have that file and also not copy

Theodora Boudale
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
April 28, 2023

Hi @rsalazari,

Thank you for your reply and the additional details about your use case. Does my suggestion work for you or are you still having any issues?

Kind regards,
Theodora

rsalazari May 2, 2023

It works, but since I have files that should not be copied for security reasons, copying them is not feasible yet. I would think it would be great if the COPY instruction would not fail even if it does not find a resource, it would just throw a waring.

Theodora Boudale
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
May 3, 2023

Hi,

I understand what you are saying; this is the only workaround I can think of at the moment, which would work if the files you want to copy are saved in a separate folder from the ones you don't want to copy.

With Docker Desktop this indeed does not fail. However, I tried installing the latest version of Docker Engine on a Linux machine, and the copy fails as well (with resource/*.txt and resource/*) if there are no files in the directory. It doesn't look like the issue is specific to Pipelines and the version of Docker in Pipelines; it looks like this is something that works with Docker Desktop but not with Docker Engine.

Kind regards,
Theodora

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
TAGS
AUG Leaders

Atlassian Community Events