GaTechThomas
GaTechThomas

Reputation: 6076

COPY in dockerfile changes from expected user to root user

I've hit a wall on trying to user the COPY command in a dockerfile. When building with --privileged, it's not a problem, but that switch is not viable from a security standpoint. Here's what's happening:

  1. List the files on the host -> they all show as user123
  2. Show user name and uid/gid in the container -> they all correspond to user123
  3. Issue a COPY inside the container
  4. List the files inside the container -> they all show as root

For the last item above, I would like the files to show as user123.

I've tried/confirmed the following:

I've also tried COPY --chown in the dockerfile, but that option isn't available because the docker server version is stuck in the stone ages (1.13).

To state the obvious, this is occurring during a docker build.

Upvotes: 3

Views: 1386

Answers (1)

anemyte
anemyte

Reputation: 20196

If you can't use COPY --chown why don't you RUN chown after copy?

RUN chown -R 123:123 file

Also why do you have to build the image on the server? You can build it elsewhere, where a more recent Docker version is available. Then deliver the image to the server via repository or through export/import.

Upvotes: 3

Related Questions