2015-05-11 15:11 GMT+02:00 Laurent Bercot <[email protected]>: > On 11/05/2015 13:52, Scott Mebberson wrote: > >> I'm working on an addition to the s6-overlay project. I want to make it >> super easy to create environment variables within a Docker container. >> > > IIRC, /var/run/s6/container_environment is meant to hold the variables > that the container is actually started with; outside interaction with > the container may rely on that (i.e. commands started with "with-contenv" > may not work correctly if that environment has been modified). I'm not > sure it's safe to do that. >
Yes, it's safe. Every time "with-contenv" is invoked, current env is dropped and the new one loaded with the current env file/vars: https://raw.githubusercontent.com/just-containers/s6-overlay/master/builder/overlay-rootfs/usr/bin/with-contenv . > But if that's what you want, you can just type > > redirfd -w 1 /var/run/s6/container_environment/env_var_name > s6-echo -- env_var_value > > If you don't want newlines just do: "s6-echo -n -- env_var_value". > and you're done. I'm not sure it justifies a specific script to > do that, unless you want to add some more processing. > > Be aware that "with-contenv" reads the environment variables > verbatim from the files, so you have to manually strip newlines and > otherwise sanitize env_var_value before storing it. > > > tr "a-z" "A-Z" >> > > You can't do that in the overlay, because there's no guarantee > that every image will have a "tr" binary. That's the reason why > everything in the overlay is written in execline and uses > s6-* binaries: no external dependencies at all, so it works with > every possible image. > Yeah, s6-overlay works in all docker images (at least the ones we tested) because it uses just binaries present in "execline", "s6" or "s6-portable-utils". > Just trust the user to use the correct filename. Also, it is valid > to use lowercase in environment variables - upper case is just a > convention used to work around a deficiency of the shell, i.e. treating > internal shell variables and environment variables the same way (which > makes it harder to tell the difference, that's why people usually > reserve full upper case for the environment). > > > But I can't get it to work. I guess redirection isn't supported? I've got >> no idea really, I'm lost! >> > > http://skarnet.org/software/execline/redirfd.html :) > > Good luck, > > -- > Laurent > >
