Container env Does not match docker inspect results

I have been struggling to figure out environment variables and how to make them persist in my container. I have come to terms that you can’t just define an environment variable in the a Dockerfile and propagate it to the container without defining it during build. Since I don’t want to actually start my container as soon as it’s built I am using the create command instead of run and starting the container later.

So I am running something like:(some flags omitted for readability)
docker create -it --name=ContainerName -e LD_PRELOAD=/usr/local/lib/faketime/

Then I inspect the container I just created to check it’s enviornment:

sudo docker inspect -f “{{ .Config.Env }}” ContainerName
[LD_PRELOAD=/usr/local/lib/faketime/ PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin]

Start the container
docker start ContainerName

docker attach -ai ContainerName

Try to find my environment variable:
No results here, just blank line

Check the envelope of the system and see it missing:

root@localhost:/# env

So the container defines this variable but it’s not actually available anywhere. Not sure how to make a simple thing like a global variable available in a container because it sure doesn’t seem to work right now.

Hi there,

I have the same problem.

That should work. At a very technical level, that should cause the environment variable to be set when the Docker environment launches the entrypoint process in the container.

What is the container actually running? LD_PRELOAD in particular is a pretty special environment variable and things that make an effort to protect the environment will frequently strip it out.

If you write this Dockerfile:

FROM ubuntu:16.04
CMD ["sh", "-c", "echo FOO is $FOO"]

Then you can

> docker build -t tmp .
> docker run tmp
FOO is bar
> docker run -e FOO=quux tmp
FOO is quux