我正在运行一个dockerized django应用程序,想将我的AWS凭证传递到我的settings.py中。因此,我在.bash_profile中设置环境变量,然后在settings.py中设置os.getenv[AWS_ACCESS_KEY_ID]
。我也尝试过os.environ[...]
。
进入外壳进行调试时,我得到:
/usr/local/lib/python3.6/os.py in __getitem__(self, key)
667 except KeyError:
668 # raise KeyError with the original key value
--> 669 raise KeyError(key) from None
670 return self.decodevalue(value)
所以我认为环境变量为None,因此无法读取。 docker / bash有问题吗?我的意思是无法访问?还是应该?还是我必须在Dockerfile中设置它?如果可以,怎么办?
非常感谢任何提示或帮助!预先感谢!
这是我的dockerfile:
FROM python:3.6-alpine
ENV PYTHONUNBUFFERED 1
RUN apk update \
# psycopg2 dependencies
&& apk add --virtual build-deps gcc python3-dev musl-dev \
&& apk add postgresql-dev \
# Pillow dependencies
&& apk add jpeg-dev zlib-dev freetype-dev lcms2-dev openjpeg-dev tiff-dev tk-dev tcl-dev \
# CFFI dependencies
&& apk add libffi-dev py-cffi \
# Translations dependencies
&& apk add gettext \
# https://docs.djangoproject.com/en/dev/ref/django-admin/#dbshell
&& apk add postgresql-client
# Requirements are installed here to ensure they will be cached.
COPY ./requirements /requirements
RUN pip install -r /requirements/local.txt
COPY ./compose/production/django/entrypoint /entrypoint
RUN sed -i 's/\r//' /entrypoint
RUN chmod +x /entrypoint
COPY ./compose/local/django/start /start
RUN sed -i 's/\r//' /start
RUN chmod +x /start
WORKDIR /app
ENTRYPOINT ["/entrypoint"]
然后我用以下命令运行docker:docker-compose -f local.yml up
我用docker-compose -f local.yml build