Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the default user of instructions in Dockerfile?

Tags:

docker

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:

  1. Is root the default user?
  2. Why $UID in Dockerfile shows nothing?

Thanks!

like image 963
KikiYu Avatar asked Oct 30 '25 12:10

KikiYu


1 Answers

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
like image 184
Adiii Avatar answered Nov 01 '25 03:11

Adiii



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!