Docker使用代理在具有其他服务的容器中运行Cron

时间:2019-01-30 18:57:19

标签: docker proxy

我在Docker容器中有一个django应用程序。我使用

font = new BitmapFont();
    font.setColor(Color.WHITE);
    font.getData().setScale(5);

    font2 = new BitmapFont();
    font2.setColor(Color.WHITE);
    font2.getData().setScale(7);

并且我在当前终端会话中使用

设置了代理变量
docker build --build-arg http_proxy=$http_proxy \
             --build-arg https_proxy=$https_proxy \
             --build-arg no_proxy=$no_proxy \
             -t <tag> .

下面是Dockerifle:

export http_proxy=http://user:pass@proxy.company.com:8099/
export https_proxy=http://user:pass@proxy.company.com:8099/
export no_proxy=*.local,localhost,169.254.169.254,*.abc.company.com,*.cloud.company.com

我还使用

运行容器
FROM artifactory.cloud.company.com/amazonlinux:2.0.20181010

ENV PIP_INDEX_URL https://artifactory.cloud.company.com/artifactory/api/pypi/pypi-internalfacing/simple/


RUN yum install -y python3 python3-devel python3-setuptools python3-pip git gcc
RUN pip3 install --upgrade --trusted-host artifactory.cloud.company.com pip setuptools
RUN amazon-linux-extras install nginx1.12
RUN yum install -y python2-pip
RUN pip2 install supervisor -i https://artifactory.cloud.company.com/artifactory/api/pypi/pypi-internalfacing/simple/ --trusted-host artifactory.cloud.company.com
RUN pip3 install uwsgi
RUN pip3 install django requests python-decouple
RUN mkdir -p /ASVDASHBOARD
# Application folder on the server with absolute path.
ADD ./ASVDASHBOARD /ASVDASHBOARD

WORKDIR /ASVDASHBOARD
RUN mkdir -p /etc/supervisor/
RUN cp ASVDASHBOARD_nginx.conf /etc/nginx/conf.d/default.conf
RUN cp ASVDASHBOARD_supervisor.conf /etc/supervisor/supervisord.conf
#RUN cp ASVDASHBOARD_supervisor.conf /etc/supervisord.d/
RUN chown -R nginx:nginx /ASVDASHBOARD && \
    mkdir -p /ASVDASHBOARD/logs/ && \
    touch /ASVDASHBOARD/logs/dashboard.log
RUN python3 manage.py makemigrations && \
    python3 manage.py migrate --run-syncdb && \
    python3 manage.py migrate

RUN python3 manage.py update_data
RUN mkdir /run/uwsgi && chmod -R 777 /run/uwsgi
EXPOSE 8080

CMD ["supervisord", "-c", "/etc/supervisor/supervisord.conf"]

现在,我想在容器中运行cron作业以运行此命令docker run -it -d --name final_dashboardd -e http_proxy -e https_proxy -e no_proxy -p 8080:8080 py37:v3 。若要仅手动运行,我将必须使用exec将Shell终端附加到容器,设置代理,然后运行命令,即可正常工作。

如何设置/传递代理以立即运行此cron作业。 我尝试过

python3 /pathtofile/manage.py update_data

哪个没用。如何在这里传递代理,因为我已连接到终端并设置了代理变量。可以,但是如何为cron设置代理。

0 个答案:

没有答案