【问题标题】:how does docker handle file creation?docker如何处理文件创建?
【发布时间】: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


【解决方案1】:

更改了我导入 mongo 的方式,并且它起作用了。在 Dockerfile 中:

#Step 1:  Import the MongoDB public key
RUN apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv EA312927
#Step 2: Generate a file with the MongoDB repository url
RUN echo "deb http://repo.mongodb.org/apt/ubuntu $(cat /etc/lsb-release | grep DISTRIB_CODENAME | cut -d= -f2)/mongodb-org/3.2 multiverse" | tee /etc/apt/sources.list.d/mongodb-org-3.2.list
#Step 3: Refresh the local database with the packages
RUN  apt-get update
#Step 4: Install the last stable MongoDB version and all the necessary packages on our system
RUN apt-get -y install mongodb-org

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-31
    • 2010-09-17
    • 2014-12-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多