问题

  1. 在写dockerfile时候环境变量写在/etc/profile上,每次进去都要执行source /etc/profile才能生效。
RUN echo 'export JENKINS_HOME=/var/jenkins_home/' >> /etc/profile
RUN echo 'export JAVA_HOME=/usr/local/jdk1.8.0_181/' >> /etc/profile
RUN echo 'export CLASSPATH=.:${JAVA_HOME}/jre/lib/rt.jar:${JAVA_HOME}/lib/dt.jar:${JAVA_HOME}/lib/tools.jar' >> /etc/profile
RUN echo 'export PATH=$PATH:${JAVA_HOME}/bin:${MAVEN_HOME}/bin' >> /etc/profile
RUN  source /etc/profile

刚开始是这样写的dockerfile文件,每次连接容器都要执行source /etc/profile才生效

解决方法

  1. 将环境变量设置在/root/.bashrc和jenkins/.bashrc上
  2. 通过env去设置,比较推荐这一种

ENV JENKINS_HOME=/var/jenkins_home JAVA_HOME=/usr/local/jdk1.8.0_181 CLASSPATH=.:${JAVA_HOME}/jre/lib/rt.jar:${JAVA_HOME}/lib/dt.jar:${JAVA_HOME}/lib/tools.jar
ENV PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/jdk1.8.0_181/bin:/usr/local/apache-maven-3.6.0/bin
Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐