Lxc does not work properly with environment variables


#1

I’m trying to run some behavior tests on my docker environment after I build my container.

For some reason, environment variables either specified on Dockerrun file or with the option “-e” are not being available on container when it is running.

docker run -d -it --name ubuntu -e “testvariable=testvalue” ubuntu bash;sleep 10
sudo lxc-attach --keep-env -n “$(docker inspect --format ‘{{.Id}}’ ubuntu)” – printenv

TERM=vt100
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
LANG=en_US.UTF-8
HOME=/home/ubuntu
DISPLAY=:99
SHELL=/bin/bash
LOGNAME=root
USER=root
USERNAME=root
MAIL=/var/mail/root
SUDO_COMMAND=/usr/bin/lxc-attach --keep-env -n a82afb6fb09e418ebb1b80da82305034daf8568013a5b478832f02ab2e05bc52 -- printenv
SUDO_USER=ubuntu
SUDO_UID=1000
SUDO_GID=1000
container=lxc

Also, I would like to understand the reason behind this outdated docker with lxc instead of native.

Plans to update to native?

Is there any way I can use updated docker with libcontainer in circleci?


#2

I’d very much like to hear an answer to this question.
I’m in the exact same position as OP, and lxc-attach is definitely not a working alternative to docker exec.

I tried nsenter too, but same problem: the environment variables are not set according to the original container you’re entering into.

EDIT: apparently nsenter provides a trick: https://github.com/jpetazzo/nsenter/pull/43


#3

I’m starting to experience the very same issue since a few hours ago. Basically, I can’t test the docker image built

from: https://circleci.com/docs/docker/#docker-exec

test:
  post:
    - docker run -d -p 3000:3000 -e "SECRET_KEY_BASE=abcd1234" circleci/hello:$CIRCLE_SHA1; sleep 10
    - curl --retry 10 --retry-delay 5 -v http://localhost:3000

The environment variables aren’t passed to the container. So my builds are red. Is something changed?


#4

Hello, @aboutlo @docteurklein @fabiocarneiro,

If you are still experiencing this issue could you please reach out to support@circleci.com so we can help you figure this out?

Best,
Zak


#5