.bash_profile不适用于docker php映像

Ali*_*nce 2 docker dockerfile

有我的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
Run Code Online (Sandbox Code Playgroud)

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

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

Boy*_*nux 5

那是因为那些(即“ RUN”和“ SHELL”)是构建指令。当您执行docker runENTRYPOINTCOMMAND正在转而执行。

docker exec但是,只需进入现有容器的名称空间并执行命令。因此,就您而言,它只是运行bash。因此,您必须再次获取个人资料。

更新:

该摘录来自man bash

启动不是登录外壳程序的交互式外壳程序时,如果存在这些文件,则bash从/etc/bash.bashrc和〜/ .bashrc中读取并执行命令。

因此,如果您将文件名更改为~/.bashrc可能有效


小智 5

发生了类似的问题,最简单的解决方案是使用-l选项对bash进行操作,使bash就像被作为登录shell调用一样。

docker run --rm -it $IMAGE /bin/bash -l
Run Code Online (Sandbox Code Playgroud)

然后bash将读入〜/ .bash_profile