Home > Net >  How to COPY all directories in one level above in Docker?
How to COPY all directories in one level above in Docker?

Time:09-21

I am trying to create an image using a dockerfile. As I saw from public repositories, People have a directory named docker. So I want to copy all my code (basicaly whole repo) into docker image. But I couldn't find the proper way. (You can see the basic file structure below.)

Directory Structure

enter image description here

So there are two main questions:

1- How can I copy all files and directories from one level above?

2- Is this approach acceptable as best practice?

Here is the docker file I have at the moment.

#This file is named as dockerfile
FROM continuumio/miniconda3
COPY . . #This line is probably faulty.
ADD environment.yml ./

RUN conda env create -f environment.yml
ENTRYPOINT [ "python","test.py"]

CodePudding user response:

It depends from where you call the docker build command. If you're in the my_repo directory, you could call

docker build -f .\docker\Dockerfile .

With the final . you define the current directory as your build context and in this case the COPY command will copy all the files into the container.

EDIT: However, for easier handling and readability, I would place the Dockerfile at the level of my_repo

  • Related