CentOS / sig-cloud-instance-images

CentOS cloud images
781 stars 563 forks source link

.bashrc is not evaluated #33

Open jackielii opened 9 years ago

jackielii commented 9 years ago

With this:

docker build --no-cache - <<EOF
FROM centos:5

RUN echo "cat .bashrc" >> /root/.bashrc
RUN bash -c "echo"
EOF

Expected result should be the content of the .bashrc right? But got nothing.

jperrin commented 9 years ago

This isn't correct. You don't have a login shell via bash here. The output comes from stdout and stderr

If you run the resulting container with --rm -it /bin/bash, you'll get the output you're expecting, but you'll also see that it's a typo, because you don't end up in /root, but instead in /

This isn't a bug.

jackielii commented 9 years ago

Thanks,

I'm aware that do docker run -it --rm image-name bash will give me the expected result. But my use case is to source a file at the beginning of my Dockerfile and the rest of the RUN command all depend on the environment variables that are set by this file. And I couldn't just use ENV directive because this file has got complex logic in it.

What the solution to this? I see the /bin/sh is actually aliased to /bin/bash. Does this bash evaluate any rc file?