【发布时间】:2017-05-11 18:57:10
【问题描述】:
我的代码将 mongo 集合转储到本地文件夹,然后上传到 s3 存储桶
cmd = "mongoexport " \
"--host " + url + \
" --port " + str(port) + \
" --username " + user + \
" --password " + password + \
" --db " + db_name + \
" --collection "
temp = cmd + name + " --out dump/" + name + ".json"
subprocess.call(temp, shell=True)
self.client.upload_file("dump/" + name + ".json", "devopsmlabbackup", "dump/" + db_name + "/" + name + "/" + str(curr_archive_count+1) + ".json")
这在我在 windows 和 ubuntu 上运行应用程序时有效,但在 docker 上运行时失败,因为 .upload_file() 找不到目录。
Dockerfile:
FROM python:2.7
# Install uWSGI
RUN pip install uwsgi
# Standard set up Nginx
ENV NGINX_VERSION 1.9.11-1~jessie
RUN apt-key adv --keyserver hkp://pgp.mit.edu:80 --recv-keys 573BFD6B3D8FBC641079A6ABABF5BD827BD9BF62 \
&& echo "deb http://nginx.org/packages/mainline/debian/ jessie nginx" >> /etc/apt/sources.list \
&& apt-get update \
&& apt-get -y install sudo \
&& apt-get -y install mongodb \
&& apt-get install -y ca-certificates nginx=${NGINX_VERSION} gettext-base \
&& rm -rf /var/lib/apt/lists/*
# forward request and error logs to docker log collector
RUN ln -sf /dev/stdout /var/log/nginx/access.log \
&& ln -sf /dev/stderr /var/log/nginx/error.log
EXPOSE 80 443
# Finished setting up Nginx
# Make NGINX run on the foreground
RUN echo "daemon off;" >> /etc/nginx/nginx.conf
# Remove default configuration from Nginx
RUN rm /etc/nginx/conf.d/default.conf
# Copy the modified Nginx conf
COPY nginx.conf /etc/nginx/conf.d/
# Copy the base uWSGI ini file to enable default dynamic uwsgi process number
COPY uwsgi.ini /etc/uwsgi/
# Install Supervisord
RUN apt-get update && apt-get install -y supervisor \
&& rm -rf /var/lib/apt/lists/*
# Custom Supervisord config
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
COPY . /deploy
WORKDIR /deploy
RUN pip install -r /deploy/requirements.txt
CMD ["/usr/bin/supervisord"]
【问题讨论】:
-
你在你的 Dockerfile 中使用
WORDIR指令吗?发布你的 Dockerfile -
@user2915097 WORKDIR /deploy
-
这段代码是如何运行的?它是在 supervisord 下运行的后台进程的一部分还是 uwsgi Web 服务器的一部分?发布您收到的 self.client.upload_file、主管配置和 uwsgi 配置的完整错误似乎相关。
标签: python mongodb docker amazon-s3