Or, in other words, do I need to run docker run -it <container> bash or docker run -it <container> bash --login to get the same environment as what they would run in?
to get the same environment as what they would run in?
I understand "As they would run by default without specfifying a command"
That will simply depend on how your container is actually configured to run:
ENTRYPOINT or CMD is configured to run a login shell, you should use a login shellENTRYPOINT or CMD is configured to run a non-login shell, you should use a non-login shellYou can identify this by running docker inspect on your container or docker image inspect which will give you ENTRYPOINT and CMD
Same principle if you first run the container then create a shell using docker exec -it bash [--login]
For example, using this Dockerfile:
FROM alpine
RUN apk add bash
RUN echo "export MYVAR=frombashrc" > /root/.bashrc
RUN echo "export MYVAR=fromprofile" > /root/.bash_profile
ENTRYPOINT ["/bin/sh", "-c"]
And running:
$ docker build . -t mybashimage
$ docker run -it --name bashcontainer mybashimage "bash --login -c 'env && sleep 60'"
HOSTNAME=4aeb776a8c56
MYVAR=fromprofile
...
In another shell while container is running:
# Running a non-login shell does not have same effect
$ docker exec -it bashcontainer bash
bash-4.4# env
HOSTNAME=5f44398152bf
MYVAR=frombashrc
...
# Running login shell doe
$ docker exec -it bashcontainer bash --login -c 'env'
HOSTNAME=5f44398152bf
MYVAR=fromprofile
...
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