The priority of loading environment variables under linux and the problem of environment variables in docker-the road to dream

Overview of environment variables under Linux:

/etc/profile: This file sets environmental information for each user of the system. When the user logs in for the first time, the file is executed and the shell settings are collected from the configuration file in the /etc/profile.d directory.
/etc /bashrc: Execute this file for every user running the bash shell. When the bash shell is opened, the file is read.

//User-level environment variables, users can override global variables
~/.bash_profile: Every user can use this file to input shell information dedicated to their own use. When the user logs in, the file is executed only once! By default, He sets some environment variables and executes the user's .bashrc file.
~/.bashrc: This file contains bash information dedicated to your bash shell, which is read when logging in and every time a new shell is opened.
~ /.bash_logout: This file is executed every time you exit the system (exit the bash shell).

The variables (global) set in /etc/profile can act on any user,
and the variables set in ~/.bashrc, etc. (Partial) Only the variables in /etc/profile can be inherited, they are "parent-child" relationship.

~/.bash_profile is interactive, login mode to enter bash operation
~/.bashrc is interactive non-login mode to enter bash operation
Usually the two settings are roughly the same, so usually the former will call the latter.

 

Docker environment variables:

It needs to be set in ~/.bashrc. If it is set in /etc/profile, you must execute source /etc/profile every time you switch users or exit the container and re-enter.

If you are making a mirror, use ENV to add environment variables when making a mirror, such as:

ENV export JAVA_HOME=/usr/java/jdk1.8.0_221-amd64
ENV export JRE_HOME=${JAVA_HOME}/jre
ENV export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
ENV export PATH=${JAVA_HOME}/bin:$PATH

 

Guess you like

Origin blog.csdn.net/qq_34777982/article/details/109767202