docker - 使用 ENV 参数设置容器 PATH

标签 docker docker-compose

我有一个 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/

相关文章:

spring - H2 控制台不适用于 Docker(远程连接 ('webAllowOthers' 被禁用)

node.js - 如何在 Docker 中运行 Iojs?

Python cv2.imshow() 不工作 : cannot connect to X server

docker - Odoo 12 docker compose 不显示已安装的额外插件

mysql - Docker compose不会为mysql8创建用户、密码和数据库

docker - 将Docker设置移至文件夹

shell - 退格后 HBase shell 崩溃

docker - 如何连接到 docker 桌面的主机以查看我的卷

mysql - Django docker 容器无法连接到 mysql 容器,错误为 "Can' t 连接到 'db' (111) 上的 MySQL 服务器"

docker-compose 运行不是最后一个图像