bsdpot / pot

pot: another container framework for FreeBSD, based on jails, ZFS and pf
BSD 3-Clause "New" or "Revised" License
341 stars 31 forks source link

[BUG] set-env does not work? #276

Closed OneOfTheJohns closed 11 months ago

OneOfTheJohns commented 11 months ago

Hi, My pot version is 0.15.5. Im trying to setup the environment variable inside of the pot, for that im using command pot set-env, but it seems that it does not work. commands to reproduce:

pot create -p test -b 12.4 -N inherit -t single
### i try to set-env before starting pot
pot set-env -p test -E TEST=test
pot exec echo $TEST
### i try to set-env after starting pot
pot start test
pot set-env -p test -E TEST=test
pot exec echo $TEST

Im quite confused, as im awaiting this command to setup environment variable inside of my Freebsd pot, either via setenv command, or directly in .profile, but it seems that it does nothing of that.

grembo commented 11 months ago

Hi @OneOfTheJohns,

The purpose of set-env is to set variables for the command executed in the pot on start (so it's in the environment of the PID of the command running inside the pot). This could either be a single process like nginx (for a thin classic container which only runs one command and ends as soon as the command ends) or persistent rc(8) style jails.

This is commonly used to configure a container, so you can pass in configuration details of a specific instance, e.g., a datacenter name, an IP address, the admin's email address, a password to use, etc.

See https://github.com/bsdpot/potluck/tree/master/consul for an example of how environment variables can be used to support provisioning a pot from an image. README.md describes how it is used, https://github.com/bsdpot/potluck/blob/master/consul/consul.d/local/bin/cook shows how it's actually applied while provisioning the pot on first start.

If you want to do something specific with those variables (e.g., add them to your .profile) you could do that of course in the image your clone from (like shown in cook or you could add your own rc script which makes use of # KEYWORD: firstboot, add something in /etc/rc.local - it's really up to you, how you would apply it).

Hope that helps answering your question.

OneOfTheJohns commented 11 months ago

Thanks @grembo for the explanation, that answers the question.