Skip to content

WORKDIR doesn't respect USER when creating directories #20295

@dmolesUC

Description

@dmolesUC

To reproduce, build an image from the following Dockerfile:

FROM centos:7
RUN mkdir -p /apps/foo
RUN useradd -d /apps/foo foo && \
    chown -R foo:foo /apps/foo
USER foo
WORKDIR /apps/foo/bar
RUN mkdir baz

Expected:

  • directory /apps/foo/bar is owned by user foo
  • directory /apps/foo/bar/baz is created

Actual:

  • directory /apps/foo/bar is owned by root

    $ ls -dal /apps/foo/bar
    drwxr-xr-x 2 root root 4096 Feb 13 00:26 /apps/foo/bar
    
  • the RUN mkdir baz step fails with

    mkdir: cannot create directory 'baz': Permission denied
    The command '/bin/sh -c mkdir baz' returned a non-zero code: 1
    

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/builderBuildkind/enhancementEnhancements are not bugs or new features but can improve usability or performance.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions