Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is my dockerfile not copying directories

Tags:

docker

in my dockerfile I have these two lines:

ADD /ansible/inventory /etc/ansible/hosts
ADD /ansible/. /ansiblerepo

The first line works, as I can run the container and see my hosts file has been populated with all the ips from my inventory file.

The second line doesn't appear to be working though. I'm just trying to copy all the files/subdirectories of ansible and copy them over to the ansiblerepo directory inside the new container.

There are no errors while building the image, but again ansiblerepo is just an empty directory and nothing has copied over to it. I assume I'm just missing a back slash or something.

like image 276
stephan Avatar asked Oct 27 '16 03:10

stephan


People also ask

Does Dockerfile copy create directories?

Docker Dockerfiles COPY InstructionAll new files and directories are created with a UID and GID of 0.

How do I copy a directory in Docker container?

You can use the docker cp command to copy the file. The first path (Source) is the path in the Docker Container and the second one is the path inside your Local System (Destination).


1 Answers

Docker ADD and COPY commands work relative to the build directly, and only for files in that directory that weren't excluded with a .dockerignore file. The reason for this is that builds actually run on the docker host, which may be a remote machine. The first step of a docker build . is to package up all the files in the directory (in this case .) and send them to the host to run your build. Any absolute paths you provide are interpreted as relative to the build directory and anything you reference that wasn't sent to the server will be interpreted as a missing file.

The solution is to copy /ansible to your build directory (typically the same folder as your Dockerfile).

like image 140
BMitch Avatar answered Oct 28 '22 21:10

BMitch