How to copy folders to docker image from Dockerfile?

I tried the following command in my Dockerfile: COPY * / and got mighty surprised at the result. Seems the naive docker code traverses the directories from the glob and then dumps the each file in the target directory while respectfully ignoring my directory structure.

At least that is how I understand this ticket and it certainly corresponds to the result I got.

  • How can I setup and deploy a database with Deis (PaaS)
  • jq returns null from curl
  • Error while publising to docker on Azure from Visual Studio 2015
  • How run Symfony commands in background Docker
  • Docker is in volume in use but no docker containers
  • why does docker have docker volumes and volume containers
  • I guess the only reason this behavior can still exist must be that there is some other way this should be done. But it is not so easy for a bear of very little brain to understand how, does anyone know?

  • Dockerfile for NGINX Web server
  • Connecting to a mysql running on a Docker container
  • Boot2docker on windows got “Permission denied” error
  • How to force a docker push on mac osx
  • Is there any definitive guide on how to pass all the arguments to Docker containers while starting a container through kubernetes?
  • Connecting to a running docker container - differences between using ssh and running a command with “-t -i” parameters
  • 2 Solutions collect form web for “How to copy folders to docker image from Dockerfile?”

    As mentioned in your ticket:

    You have COPY files/* /test/ which expands to COPY files/dir files/file1 files/file2 files/file /test/.
    If you split this up into individual COPY commands (e.g. COPY files/dir /test/) you’ll see that (for better or worse) COPY will copy the contents of each arg dir into the destination directory. Not the arg dir itself, but the contents.

    I’m not thrilled with that fact that COPY doesn’t preserve the top-level dir but its been that way for a while now.

    so in the name of preserving a backward compatibility, it is not possible to COPY/ADD a directory structure.

    The only workaround would be a series of RUN mkdir -p /x/y/z to build the target directory structure, followed by a series of docker COPY (one for each folder to fill).

    use ADD instead of COPY. Suppose you want to copy everything in directory src from host to directory dst from container:

    ADD src dst

    Note: b will be automatically created in container.

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.