I have done an experiment to check this out. The following is my Dockerfile:
FROM ubuntu:bionic
RUN echo $UID > a.out && echo "hello" > a.out
RUN useradd -m user
RUN echo $UID > b.out
USER user
The result of a.out and b.out is shown below.
user@39370ee77a16:/$ cat a.out
hello
user@39370ee77a16:/$ cat b.out
My question is:
Thanks!
It depend upon the base image, but in you case the default user is root. you can verify from the base image or inside Dockerfile.
FROM ubuntu:bionic
RUN whoami
In your case, you see hello because you override the content, try with
RUN echo $UID >> a.out && echo "hello" >> a.out
You can change user using
USER my_user
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With