win7 docker java开发环境变量,Docker从命令或文件中设置环境变量

I need to set an environment variable CLASSPATH. In that variable I need to set the result of a command:

hadoop classpath --glob

This will return a ton of java libraries and they all need to get set into that CLASSPATH variable. The big problem is that I can only run this command after the docker build is complete, meaning I have to do it in the ENTRYPOINT. But I just cant get it working. I tried differen approaches:

ENTRYPOINT ["sh", "-c", "export CLASSPATH=$(hadoop classpath --glob) ...."

ENTRYPOINT ["sh", "-c", "set CLASSPATH=$(hadoop classpath --glob) ...."

ENTRYPOINT ["sh", "-c", "CLASSPATH=$(hadoop classpath --glob) ...."

ENTRYPOINT ["sh", "-c", "/bin/bash && export CLASSPATH=$(hadoop classpath --glob) ...."

But nothing of it is working. The command itself is working, I tested it using:

ENTRYPOINT ["sh", "-c", "echo $(hadoop classpath --glob) >> /tmp/classpath.tmp ...."

This file contains the correct content after startup. So there is just a problem with setting and persisting the environment variable. How am I supposed to set the environment variable? Usually you use something like

ENV CLASSPATH="some classpath"

But here I cant use the ENV statement since it wont process the command $(hadoop classpath --glob)

解决方案

The only working solution for that problem was to not use an ENTRYPOINT in the Dockerfile at all.

Create entrypoint.sh

Add all the stuff you need (exports for example) into that sh file

Copy entrypoint.sh in dockerfile to /

Execut entrypoint.sh in docker run or dockercompose

Attention: you need to execute it by . /entrypoint.sh. Otherwise it wont work.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值