I am building Docker Image FROM node:8.9.3-alpine
(which is Debian) and then running it as usual and passing parameters like this:
docker run -dt \
-e lsRegion=${bamboo_lsRegion} \
-e lsCluster=${bamboo_lsCluster} \
Then inside that container I am exporting some variables and when I echo them, I can see proper value
export lsEnv=${lsEnv:-'dev'}
Later in scripts I run python script and when I run the print(os.environ)
I can see all the variables from docker run
like lsRegion
but I do not see the newly exported one like lsEnv
.
I already found and tried to solve with this: Python: can't access newly defined environment variables by calling the source ~/.bashrc
but I cannot find that file.
I have tried
~/.bashrc
/etc/bash.bashrc
/root/.bashrc
But neither of those exist (also does not know if this solve my problem) and it ends with this error message /app/deploy.sh: source: line 16: can't open '/root/.bashrc'
More reproducible example:
Dockerfile
FROM node:8.9.3-alpine
RUN apk add --no-cache \
python \
py-pip \
ca-certificates \
openssl \
groff \
less \
bash \
curl \
jq \
git \
zip \
build-base \
&& pip install --no-cache-dir --upgrade pip awscli \
&& aws configure set preview.cloudfront true
ENV TERRAFORM_VERSION 0.11.10
RUN wget -O terraform.zip https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_linux_amd64.zip && \
unzip terraform.zip -d /usr/local/bin && \
rm -f terraform.zip
RUN apk -v --update add python py-pip
RUN pip install --upgrade awscli
RUN pip install --upgrade boto3
COPY ./build.variables /app/build.variables
COPY ./aws/taskdef/template.json /app/template.json
COPY ./deploy.sh /app/deploy.sh
COPY ./deploy.py /app/deploy.py
COPY ./terraform /app/terraform
CMD ["sh", "/app/deploy.sh"]
deploy.sh
#!/bin/bash -x
cd /app/terraform
./run-terraform.sh
cd ..
python /app/deploy.py
terraform/run-terraform.sh
...
export lsEnv="NotThere"
...
python script
#!/usr/bin/env python
import os
print(os.environ)
The print will show lsRegion
or lsCluster
but it will not show the lsEnv