Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

untymage's avatar

Docker COPY copies as root even i set USER

RUN useradd -ms /bin/bash --no-user-group -g 1000 -u 1337 alex

USER alex

WORKDIR /var/www/html

COPY composer* .

COPY  . .

I set USER to alex before COPY , But all the files will created as root, Why ? (WSL2)

0 likes
3 replies
Sinnbeck's avatar
Sinnbeck
Best Answer
Level 102

Try this instead

Copy --chown alex:alex composer* . 
untymage's avatar

@Sinnbeck It working thanks, But can you say why is that ? Because i recall i saw some turorial that they set USER and dont need chown

Please or to participate in this conversation.