I'm using docker-maven-plugin. And it said -
"By default the plugin will try to connect to docker on localhost:2375. Set the DOCKER_HOST environment variable to connect elsewhere.
DOCKER_HOST=tcp://<host>:2375
Other docker-standard environment variables are honored too such as TLS and certificates.".
After I protect the Docker daemon socket reference to https://docs.docker.com/engine/security/https/. I think I need to set some variables like DOCKER_TLS_VERIFY="1" and also variable which is used to locate ca.pem file. So where could I find these docker-standerd environment variables?
You would find (and set) them on the same user that is running the docker-client.
EG:
nick#primestorage01:~$ set | grep DOCKER
DOCKER_HOST=terrorbyte:2376
DOCKER_TLS_VERIFY=true
You can do that many ways for an interactive login. One way is via a .bashrc file. (assuming you are using bash)
In .bashrc, you can add these lines:
#docker
export DOCKER_HOST=terrorbyte:2376
export DOCKER_TLS_VERIFY=true
If this is some sort of automation, depending on your methodology .bashrc won't be called (Specifically, if it's a non interactive shell such as via ssh host COMMAND. In this case, you'll need to set the environment variables another way.
PS, make sure you also put the certificates in the expected directory to make your life easier. The expected directory is ~/.docker
Related
Is it possible to have a global environment variable in bash?
If not, is it possible to have all terminals run a command such as source ~/.zshrc (i use zsh) that i can place a default set of env vars to?
Short version is that i have DB access to local, stage and prod servers. While debugging it is common for me to point my app to the stage DB's and less common to point at prod servers but it does happen (with a read only credential set). The DB credentials are set in environment vars, and i want a command i can enter in a single terminal window that will update all my DB credentials in all terminal instances. Thoughts?
I dont think this is possible, but worth asking.
Thanks.
Please I have a problem when I try to reload bash profile located in /etc/profile.
I tried to load it in many ways, from
command: . /etc/profile and with script file with script module and shell as well.
Ansible give my changed status for all, but when I tried to echo the variables inside the profile eg echo $myname they print nothing after finishing execution in playbook.
when I tried to load it again with terminal . /etc/profile the variables is loaded and I can echo it's value.
also I make a script file inside the profile.d directory and load it with Ansible nothing happens.
ps. full root permissions is given with become and --ask-become-pass
parameter. I'm using vagrant box with centos 7 X64.
Thank you...
1) Sourcing the profile will only be good for a single task.
For example, if your personal profile (I'm not getting to /etc/profile yet) sets myname=Ameen, then in the following code, the first task should echo your name, but the second should not:
- shell: 'cd; . ./.bash_profile; echo "[$myname]"`
- shell: 'echo "[$myname]"'
Every task is a distinct environment. Variables set in a local shell environment will not be available for another environment that connects later but does not set them again for itself.
My output:
[Ameen]
[]
2) bash uses .bash_profile, which typically sources ~/.bashrc, which usually sources /etc/bashrc.
In ksh it's usually ~/.profile, ~/.kshrc, and /etc/profile, though all of these are obviously configurable, just convention that can be totally done differently on a given system, though you should consider why.
3) Are you really expecting myname to be set in the global profile all users source?
Or is that just an example for your question?
Ansible load my Variables into my global profile, it's ok not changed as it's already placed in that profile
I pass the script in same environment, so the java read the variables successfully
I'm trying to connect to a remote server using Golang SSH package, but there's a SOCKS between my workstation and this remote server.
I'm able to connect to the server by simply setting a LD_PRELOAD and LD_LIBRARY_PATH and then running:
$ export LD_PRELOAD="/path/to/lib"
$ export LD_LIBRARY_PATH="/path/to/lib"
$ ssh user#hostname
But when I set these variables within the Go code, it doesn't work:
os.Setenv("LD_PRELOAD", "/path/to/file")
os.Setenv("LD_LIBRARY_PATH", "/path/to/file")
If I set these variables within the Go code and try the following, it works:
ssh := exec.Command("ssh", "hostname")
output, _ := ssh.Output()
fmt.Println(string(output))
The ssh PermitUserEnvironment is set as yes
Is there any way to "force" the Golang SSH to use these environment variables?
(Edit: This answer does not necessarily apply to Go 1.8 and above. See comments for discussion)
LD_PRELOAD and LD_LIBRARY_PATH are environment variables processed by the dynamic linker when a program is starting up. If you set those environment variables inside the program, they don't have an effect on the program itself since the linker didn't see them.
On the other hand, the environment variables will affect external applications that you run (the ssh command for example) from within the program, since the linker is given control to resolve the shared libraries that the application uses.
If you instead set those environment variables before running the Go program, I think you'll have the desired effect. (This is only applicable if the compiled program is linked to the shared standard C library. See #JimB's comments below for more details.)
I'm using the oh-my-zsh dotenv plugin, which loads .env file, if it exists, whenever I cd into a project directory.
I know it works because I can see my custom environment vars set when I run the set cmd.
I can can also echo my custom environment variable from command line:
$ echo $FOO
'foo'
However, I cannot access this environment variable via the env command or Ruby:
$ irb
2.4.1 :001 > ENV['FOO']
nil
How can I make sure environment variables loaded from my .env are accessible from Ruby?
Contrary to what is stated in the documentation of dotenv, you actually need to use the export keyword within the .env file in order to make the parameters available to the environment, e.g.
export FOO=foo
The only exception would be, if the parameter was already an environment variable. For example if it had been exported in ~/.zshrc or if it was already part of the environment zsh got when it started (e.g. PATH or HOME).
All dotenv does is automatically sourcing any .env file when changing into a directory. There is no additional "magic". That means .env needs to be a valid zsh script and its content is run in the context of the current shell session (essentially as if you typed it manually).
It also means that the usual rules apply. That is, just settings parameters makes them available to the current shell context only. In order to make them available as environment variables they need to be exported (either before, during or after being set). So unless a parameter has already been exported before, export is not really "optional" in .env.
I've been having proxy issues with npm and git.
Looks like the proxy is set as an environment variable in Bash
If I check with
env | grep -i proxy
I can see the proxy settings.
I can unset the proxy with
unset http_proxy
unset https_proxy
unset ftp_proxy
This only appears to last as long as the terminal window is open.
If I close and reopen the terminal the proxy is back again.
Is is it possible to delete the proxies when I'm out of office and then recreate them when I need them?
You first need to find out where these environment variables are defined in your case.
Typically they are set in the ~/.bash_profile file (Mac OS X) or ~/.bashrc file (Linux). Since you tagged the question with osx, I assume that in your case they are set in ~/.bash_profile.
Please check whether this file defines these variables. You can either do that using Finder (you need to show hidden files), or from a terminal by running cat ~/.bash_profile. Feel free to post the output in your question.
There's a small chance that they are defined in a system-wide file like /etc/bashrc. Feel free to check that file as well.
If you need to define/undefine the variables on a regular basis, I recommend that you create a script for each defining/undefining and place it in a location like ~/bin. Then you can simply call the respective script when you open a new shell.
I handle this through the Bash-it framework. In my fork, I have added a proxy plugin that provides functions for this. Feel free to give this a try: https://github.com/nwinkler/bash-it/blob/master/plugins/available/proxy.plugin.bash
To answer your other question: There's no easy way to automatically detect and change the presence of a proxy from a shell window.