I tried to use --env to pass environment variable to container, the command is like:
docker run --env P4EDITOR=“vim” -d -P -h ${HOSTNAME} -v /home/p4:/home/p4 myimage
(My image will start sshd service)
However, when I login container with ssh, I found the env variable was not passed in.
env|grep P4EDITOR
Anybody know why?
docker version
Client version: 1.7.1
Client API version: 1.19
Go version (client): go1.4.2
Git commit (client): 786b29d/1.7.1
OS/Arch (client): linux/amd64
Server version: 1.7.1
Server API version: 1.19
Go version (server): go1.4.2
Git commit (server): 786b29d/1.7.1
OS/Arch (server): linux/amd64
What happens when you docker exec into the container? The ENV VAR should be there. When you ssh into the container, you connect via pseudo terminal and a different environment.
I’m not sure what best practice is for this situation, but you can add this to your Dockerfile: RUN echo ‘export P4EDITOR=“vim”’ >> /etc/profile.d/vim_env.sh
All files in /etc/profile.d should get sourced. Let me know how it works out for you. You can also copy the .sh file instead of running echo every time you build a container.
Thanks for your suggestion, but besides P4EDITOR, I still have some account env variable such as P4USER, each user should be able to ssh to the container, then do some work with his own account, I cannot hardcode it in dockerfile.