moby: -link environment variables don't appear in SSH session

Info

core@core ~> docker -v
Docker version 0.6.5, build 3ff8459
core@core ~> uname -a
Linux core 3.11.0-12-generic #19-Ubuntu SMP Wed Oct 9 16:20:46 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux
core@core ~> cat /etc/init/docker.conf
description "Docker daemon"

start on filesystem and started lxc-net
stop on runlevel [!2345]

respawn

script
        /usr/bin/docker -d -icc=false
end script
core@core ~> sudo service docker restart
docker stop/waiting
docker start/running, process 12524

MySql container

core@core ~> docker run -d -p 127.0.0.1:5502:3306 -p 127.0.0.1:4503:22 -name mysql -expose 3306 firstplace/mysql "/usr/bin/supervisord"
390a3695f1c3

Apache container

core@core ~>
docker run -d -p 127.0.0.1:5501:80 -p 127.0.0.1:4502:22 -name apache -link mysql:db -v /opt/docker/mounts/webroot/main/:/webroot:rw firstplace/apache /usr/bin/super
visord
abfa284ce525

Results

core@core ~> docker ps
ID                  IMAGE                      COMMAND                CREATED              STATUS              PORTS                                              NAMES
abfa284ce525        firstplace/apache:latest   /usr/bin/supervisord   24 seconds ago       Up 23 seconds       127.0.0.1:4502->22/tcp, 127.0.0.1:5501->80/tcp     apache
390a3695f1c3        firstplace/mysql:latest    /usr/bin/supervisord   About a minute ago   Up About a minute   127.0.0.1:4503->22/tcp, 127.0.0.1:5502->3306/tcp   apache/db,mysql
core@core /v/log> ssh dockerApache
Welcome to Ubuntu 12.04 LTS (GNU/Linux 3.11.0-12-generic x86_64)

 * Documentation:  https://help.ubuntu.com/
Last login: Wed Nov  6 09:12:12 2013 from 172.17.42.1
root@abfa284ce525:~# env
TERM=xterm-256color
SHELL=/bin/bash
SSH_CLIENT=172.17.42.1 32868 22
SSH_TTY=/dev/pts/0
USER=root
MAIL=/var/mail/root
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
PWD=/root
LANG=en_US.UTF-8
SHLVL=1
HOME=/root
LOGNAME=root
SSH_CONNECTION=172.17.42.1 32868 172.17.0.3 22
_=/usr/bin/env

Any pointers as to what the issue might be?

About this issue

  • Original URL
  • State: closed
  • Created 11 years ago
  • Comments: 17 (7 by maintainers)

Most upvoted comments

So!

Environment variables not appearing in SSH or lxc-attach

This is expected. SSH wipes out the environment as part of the login process.

One way to work around it is to dump the environment variables in /etc/environment (e.g. env | grep _ >> /etc/environment) before starting Supervisor. Further “login processes” should source this file, and tada! There is your environment.

For lxc-attach, the fix is similar: dump environment, then source if when you start lxc-attach – or have lxc-attach start a proper login process.

Environment variables not appearing in Supervisor subprocesses

This shouldn’t happen, as explained here: http://supervisord.org/subprocess.html#subprocess-environment

If you see that it happens, it would be nice to provide a minimal Dockerfile showing how to reproduce.

Linked networking not available

Before digging further – are you sure that there is something listening on port 3306 in this container? You could try to reproduce using socat or netcat to have something with less moving parts, for instance.

Thank you!