Skip to content

Instantly share code, notes, and snippets.

@ashb
Last active November 2, 2016 16:39
Show Gist options
  • Save ashb/3215423fa25899bf01b5eafc028a9f6a to your computer and use it in GitHub Desktop.
Save ashb/3215423fa25899bf01b5eafc028a9f6a to your computer and use it in GitHub Desktop.
FROM alpine
RUN ls /etc/profile.d /usr/local/bin /usr
COPY resources/etc/ /etc
COPY resources/usr/ /usr
RUN ls /etc/profile.d/ /usr/local/bin /usr
mkdir -p resources/etc/profile.d/ resources/usr/local/bin
touch resources/etc/profile.d/my_vars.sh resources/usr/local/bin/my-script
docker build -t test .
@ashb
Copy link
Author

ashb commented Nov 2, 2016

Docker behaves really oddly (or at least not how I wanted) when copying a directory under the src of COPY (ADD behaves the same).

This is slightly hard to describe, but essentially when docker is copying in a nested directory it replaces it, rather than copying the files in one-by-one. This means you can't easily copy in many files and merge them with ones existing in the layer for many directories at once.

The output of the first RUN shows some existing files in /etc/profile.d:

 ---> Running in c44e4d25c8f7
/etc/profile.d:
color_prompt

/usr:
bin
lib
local
sbin
share

/usr/local/bin:
 ---> 22b5892e616d
Removing intermediate container 17afb2eae3ba```

Notice how there is a file in `/etc/profile.d` and many under `/usr`.

After we have copied we run the list commands again:

Step 5 : RUN ls /etc/profile.d/ /usr/local/bin /usr
---> Running in dca4ed2024f7
/etc/profile.d/:
color_prompt
my_vars.sh

/usr:
bin
lib
local
sbin
share

/usr/local/bin:
my-script
---> 8bf17bf8dd66


The other dirs in `/usr` are kept, but the whole of `/etc/profile.d` was replaced with just the one we copied in.

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