Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
3 views
in DevOps and Agile by (2.3k points)

My Dockerfile has four COPY layers:

COPY README.md ./
COPY package.json ./
COPY gulpfile.js ./
COPY __BUILD_NUMBER ./

How can I copy all of these files by using just one layer instead?

I also tried this:

COPY [
    "__BUILD_NUMBER ./",
    "README.md ./",
    "gulpfile ./",
    "another_file ./",
]

2 Answers

0 votes
by (6.9k points)
edited by

Try this command out:
COPY README.md package.json gulpfile.js __BUILD_NUMBER ./

or

COPY ["__BUILD_NUMBER", "README.md", "gulpfile", "another_file", "./"]

You can also make use of the wild card characters in your sourcefile.

Keep in mind that directories are a bit special, so when you write:

COPY dir1 dir2 ./

it actually works like this

COPY dir1/* dir2/* ./

try out docker training course, and learn with first hand experience from people who have had years of knowledge in docker

0 votes
by (1.7k points)

Dockerfiles can be used to create Docker images with several copy commands using one copy layer: 

COPY README.md package.json gulpfile.js __BUILD_NUMBER . 

In this example, the following command M owl’s copy skillet allows you to copy files into the current working directory from multiple sources and replaces the need to use multiple copy commands in a single layer.

COPY gives you the ability to copy several files from a computer to a particular directory while ensuring the correct ordering of these files so that all of them are included within the proper layer.

The syntax you used with square brackets isn’t allowed and throws an error in a Dockerfile. Instead, simply provide each file as the last part of a COPY command, separated with spaces, especially the part of the commands above.

1.2k questions

2.7k answers

501 comments

693 users

Browse Categories

...