.bash_profile不能用于docker php image

有我的Dockerfile

 # https://hub.docker.com/_/php/ FROM php:5.5.23-fpm USER www-data ADD .bash_profile /var/www/.bash_profile SHELL ["/bin/bash", "-c"] RUN source /var/www/.bash_profile 

然后,在容器build好后,我运行docker exec -it CONTAINER_NAME bash我没有看到我的别名定义在/var/www/.bash_profile 。 但是如果我手动执行source /var/www/.bash_profile – 一切正常。

同样的问题在这里描述: https : //github.com/docker/kitematic/issues/896但没有答案。

那是因为那是(即“RUN”和“SHELL”)是build立指令。 当你执行docker runENTRYPOINTCOMMAND正在被执行。

docker exec如何进入一个现有的容器的命名空间,并执行一个命令。 所以在你的情况下,它只是运行bash 。 这就是为什么你必须再次获取你的个人资料。

更新:

这个片段是从man bash

当一个不是loginshell的交互式shell被启动时,如果这些文件存在,bash将从/etc/bash.bashrc和〜/ .bashrc中读取和执行命令。

所以在你的情况下,如果你改变文件名~/.bashrc可能工作