Dockerfile avoid unnecessary files to be copied CKS Challenge 2

  1. Avoid copying the ‘Dockerfile’ and other unnecessary files and directories in to the image. Move the required files and directories (app.py, requirements.txt and the templates directory) to a subdirectory called ‘app’ under ‘webapp’ and update the COPY instruction in the ‘Dockerfile’ accordingly.

Need some help on the same. I copied files/folder except Dockerfile under /webapp/app. But still this step is failing

COPY [^Dockerfile]* /webapp/app/
COPY templates /webapp/app/templates

How to go about the same ?.

rgds
Balaji

I couldn’t find syntax for using regex syntax in either the COPY or ADD commands in Docker. But you don’t need them; this is why the challenge tells you to:

  1. Avoid copying the ‘Dockerfile’ and other unnecessary files and directories in to the image. Move the required files and directories (app.py, requirements.txt and the templates directory) to a subdirectory called ‘app’ under ‘webapp’ and update the COPY instruction in the ‘Dockerfile’ accordingly.

By putting files other than Dockerfile in the sub directory, you can just copy from the subdirectory to get the result they ask you for.

@rob_kodekloud Thanks for the response following also didn’t help

COPY app.py, requirements.txt /webapp/app/
COPY templates /webapp/app/templates

That’s not what they mean. They mean that in the directory that contains the Dockerfile, create a directory called “app”, and move the files you want to have on the image into that directory. Then you move the files from the app directory into the image with the COPY command, as so:

COPY ./app /opt

You can find the details in the CKS repo, in the section on the CKS Challenges.

1 Like

Avoid copying the ‘Dockerfile’ and other unnecessary files and directories in to the image. Move the required files and directories (app.py, requirements.txt and the templates directory) to a subdirectory called ‘app’ under ‘webapp’ and update the COPY instruction in the ‘Dockerfile’ accordingly.

The above sentence clearly means app folder or directory under webapp, this is very ambiguous and poorly worded. I now understand that app folder which should be existing under webapp should be copied to /opt within the image.

It could indeed be better worded. But given it’s sort of an odd thing to do, it was going to be somewhat awkward to write.