3

I am trying to replace some files in a folder in a docker image. I am using the following command inside Dockerfile:

COPY /home/adietz/Work/20_BSP/Jenkins/venvs/linux_selenium/lib/python2.7/site-packages/browsermobproxy /usr/local/lib/python2.7/dist-packages/browsermobproxy

which results in an error

Step 4/12 : COPY /home/adietz/Work/20_BSP/Jenkins/venvs/linux_selenium/lib/python2.7/site-packages/browsermobproxy /usr/local/lib/python2.7/dist-packages/browsermobproxy
lstat home/adietz/Work/20_BSP/Jenkins/venvs/linux_selenium/lib/python2.7/site-packages/browsermobproxy: no such file or directory

Replacing COPY with ADD results in the same error. Also the following command

COPY /home/adietz/Work/20_BSP/Jenkins/venvs/linux_selenium/lib/python2.7/site-packages/browsermobproxy /usr/local/lib/python2.7/dist-packages/

and gives identical(!) error.

Both paths are folders. The folder in the docker image already exists; I just want to replace the files.

What am I doing wrong here...?

Alex
  • 41,580
  • 88
  • 260
  • 469
  • Possible duplicate of [Dockerfile COPY instruction failing?](https://stackoverflow.com/questions/28057842/dockerfile-copy-instruction-failing) – David Maze Aug 21 '18 at 10:42
  • Its related to that, but not a duplicate. In the link its about expanding `$HOME`, which is unrelated to the issue described in this question... – Alex Aug 21 '18 at 11:32
  • The two answers that aren't the accepted answers, also answer this question. – David Maze Aug 21 '18 at 11:34
  • yes. But a user might miss the answers when probably looking for something differently... – Alex Aug 21 '18 at 11:49

2 Answers2

2

It seems you cannot use absolute paths in the COPY command AND you can only copy files which are inside the folder you are running the docker command.

So to copy these files you have to do e.g. the following steps

cp -r /home/adietz/Work/20_BSP/Jenkins/venvs/linux_selenium/lib/python2.7/site-packages/browsermobproxy .

and then add to the Dockerfile:

COPY browsermobproxy/ /usr/local/lib/python2.7/dist-packages/

A symbolic link also does not work...

Chris
  • 3,619
  • 8
  • 44
  • 64
Alex
  • 41,580
  • 88
  • 260
  • 469
  • Docker's docs do mention this - `[...] if they are files or directories, their paths are interpreted as relative to the source of the context of the build... The path must be inside the context of the build` https://docs.docker.com/engine/reference/builder/#copy - agree though it's a weird thing that they do – Sathyajith Bhat Aug 21 '18 at 08:00
0

I had this same issue and realized that COPY or ADD won't work with node_modules that are referenced instead of directly installed into the project. When I switched this it worked for me.

bguiz
  • 27,371
  • 47
  • 154
  • 243
johnkhigginson
  • 123
  • 1
  • 14