关于docker容器环境变量探讨---以gitlabrunner 为例

零 摘要

一 环境信息

二 准备知识

2.1 linux shell

https://www.vanimpe.eu/2014/01/18/different-shell-types-interactive-non-interactive-login/

2.1.1 A login shell

A login shell is the shell that is run when you log in to a system, either via the terminal or via SSH.

Why is this important? If you run a login shell it executes a number of files on startup. This can influence how your system behaves and you have to put your environment variables in these files. The files that are run are

.profile
.bash_profile
.bash_login

2.1.2 An interactive shell

An interactive shell is when you type in the name of the shell after you have logged in to the system. For example
bash
will start an interactive bash shell.

An interactive (bash) shell executes the file .bashrc so you have to put any relevant variables or settings in this file.

2.1.3 A non-interactive shell

A non-interactive shell is a shell that can not interact with the user. It’s most often run from a script or similar. This means that .bashrc and .profile are not executed. It is important to note that this often influences your PATH variable. It is always a good practice to use the full path for a command but even more so in non-interactive shells.

2.1.4 Detect the type of shell, BASH only

You can detect if you are in an interactive or non-interactive shell with

	[[ $- == *i* ]] && echo 'Interactive' || echo 'not-interactive'

To detect if you are in a login shell or not you have to use the shopt command.

shopt -q login_shell && echo 'login' || echo 'not-login'

or

shopt | grep login_shell

2.2 docker exec 默认登录方式

你可能感兴趣的:(docker,bash,linux)