Usign podman container with AlmaLinux on board.
I need to setup a set of environment variable after starting the container. So I put into the container a script setenv.sh
with contents:
#!/bin/sh
export MYVAR=value
echo $MYVAR
Now I am running the container:
$ podman run --rm -it -init almatest bash
% /opt/myapp/bin/setenv.sh
value
% echo $MYVAR
% env | grep MYVAR
%
Where is my variable? What is going on?
Edit: Executing the script with .
or source
does prevent the environment variables from disappearing. Ok, I gues that answers my original question.
I know about the -env
for the podman, but cannot use it - the container is a test environment for the production which would not have a podman. I need to do all setups from inside the container.
I know where I went wrong.
The setup.sh
is a script which is supposed to be run first. And I thought about it, like it is a .bashrc
, so export
in the setup.sh
should work as in .bashrc
. And that was the source of my mistake.
The intended role of the script is not a real one.
So the call of setup.sh
should be done by source
command.