Home > front end >  $PATH of the new user created is not considered in my dockerfile
$PATH of the new user created is not considered in my dockerfile

Time:09-17

My Dockerfile looks like that :

FROM ubuntu:focal
RUN adduser carlos --disabled-password --gecos GECOS
USER carlos
RUN echo "export PATH=\"/var/www/:$PATH\"" >> /home/carlos/.bashrc 
RUN id
RUN echo $PATH

The "RUN id" command well returns that I'm logged as carlos.

When i build the image, the $PATH (last instruction of the dockerfile) is still a non modified PATH. Why that ?

Sending build context to Docker daemon  14.85kB
Step 1/6 : FROM ubuntu:focal
 ---> a0ce5a295b63
Step 2/6 : RUN adduser carlos --disabled-password --gecos GECOS
 ---> Running in b8f855a48225
Adding user `carlos' ...
Adding new group `carlos' (1000) ...
Adding new user `carlos' (1000) with group `carlos' ...
Creating home directory `/home/carlos' ...
Copying files from `/etc/skel' ...
Removing intermediate container b8f855a48225
 ---> 1ed7829e2b12
Step 3/6 : USER carlos
 ---> Running in 556f98167d89
Removing intermediate container 556f98167d89
 ---> e41d82f717b0
Step 4/6 : RUN echo "export PATH=\"/var/www/:$PATH\"" >> /home/carlos/.bashrc
 ---> Running in a4a0f3f3b96b
Removing intermediate container a4a0f3f3b96b
 ---> 512f42df7dfb
Step 5/6 : RUN id
 ---> Running in b5f12c0926f0
uid=1000(carlos) gid=1000(carlos) groups=1000(carlos)
Removing intermediate container b5f12c0926f0
 ---> a97a4b0b476d
Step 6/6 : RUN echo $PATH
 ---> Running in 5b4e844c87ec
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
Removing intermediate container 5b4e844c87ec
 ---> ef977ae5591d
Successfully built ef977ae5591d
Successfully tagged myimage:latest

P.S : When i run the container (docker run -it <ID_of_the_container>), it well propose a bash environment logged as carlos and if I do "echo $PATH", it shows the good path of carlos (with the modification written in the docker file).

CodePudding user response:

Try the following:

ENV PATH="/var/www/:${PATH}"
RUN echo $PATH >> /home/carlos/.bashrc  # can be omitted as it has no effect, unless you need it for some reason 
  • Related