Skip to content

Instantly share code, notes, and snippets.

@kelnos
Created November 26, 2019 04:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kelnos/2eca5fc219df80a9585d83bf9f5a8415 to your computer and use it in GitHub Desktop.
Save kelnos/2eca5fc219df80a9585d83bf9f5a8415 to your computer and use it in GitHub Desktop.
Dockerfile COPY is weird

So I do some docker things:

$ ls project
README.md src
$ ls project/src
main test
$ cat Dockerfile
# ... other stuff...
WORKDIR /work
COPY /project/* ./
RUN ls
# ... other stuff
$ docker build .
# ...... stuff
Step 5/50 : COPY /project/* ./
 ---> 212131bcda
Step 6/50 : RUN ls
 ---> Running in deadbeef
README.md main test

Wat. I expect the contents of /work to be README.md and src. Why has docker copied README.md as is, and then sees a directory (src), descends into it, and starts copying from there? That makes no sense. No (reasonable?) shell would behave that way.

The "correct" formulation seems to be COPY /project/. ./, which, ok, that's valid, but... sigh.

@foobarbecue
Copy link

foobarbecue commented Feb 5, 2021

Yeah docker COPY is bizarre. I dunno what they were thinking. (I googled "docker COPY is weird" looking for some kind of explanation and ended up here)

@feisuzhu
Copy link

feisuzhu commented May 6, 2021

Yeah docker COPY is bizarre. I dunno what they were thinking. (I googled "docker COPY is weird" looking for some kind of explanation and ended up here)

Same here

@patsimm
Copy link

patsimm commented Jan 10, 2023

Yeah docker COPY is bizarre. I dunno what they were thinking. (I googled "docker COPY is weird" looking for some kind of explanation and ended up here)

Same here

Same here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment