Issue while using docker exec to attach to containers


In my Dockerfile, I have declared a script “” to be run at ENTRYPOINT. looks like this -
export PATH=$PATH:/opt/bin
echo “ mynode” >> /etc/hosts
useradd -u $UID -m -s /bin/bash $USER
su $USER

  1. To spin a container I use -
    docker run -it --detach --name=containername -e USER=${USER} -e UID=id -u -e GID=id -g imagename bash
  2. I do a docker start and then attach to the container ‘containername’. Now, when I echo $PATH, I see /opt/bin present in the PATH
  3. I create another session to the same container using docker -exec -u $USER containername bash. Now, when I am inside the container I do not see PATH containing the /opt/bin. I am sure is running because I can see in /etc/hosts.

What am I missing here? Any help, will be greatly appreciated.