我有一个 docker-compose 文件,其中包含以下内容:
environment:
DOCUMENT_ROOT: /var/some/dir
我想将该路径添加到我的容器中。 在我的 DockerFile 中我添加:
RUN echo "export PATH=$PATH:${DOCUMENT_ROOT}" >> /root/.bashrc
但是这不起作用。 ENV 参数似乎不可用。
有什么问题吗?
亚龙
最佳答案
ARG some_variable_name
RUN echo "export PATH=$PATH:${some_variable_name}" >> /root/.bashrc
您应该在 Dockerfile 中使用 ARG
并在构建命令中设置参数:
docker build --build-arg some_variable_name=a_value
ARG is only available during the build of a Docker image (RUN etc), not after the image is created and containers are started from it (ENTRYPOINT, CMD). You can use ARG values to set ENV values to work around that.
或者在 docker-compose 中:
version: '3'
services:
somename:
build:
context: ./app
dockerfile: Dockerfile
args:
some_variable_name: a_value
Understanding Docker Build Args, Environment Variables and Docker Compose Variables
关于docker - 使用 ENV 参数设置容器 PATH,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55161713/