【发布时间】:2026-02-05 01:50:02
【问题描述】:
我正在尝试在 docker 容器中运行我的 django 应用程序,其中包含从 Amazon S3 提供的静态文件。当我在 Dockerfile 中运行 RUN $(which python3.4) /home/docker/code/vitru/manage.py collectstatic --noinput 时,我从 Amazon S3 收到 403 Forbidden 错误,并带有以下响应 XML
<?xml version="1.0" encoding="UTF-8"?>
<Error>
<Code>RequestTimeTooSkewed</Code>
<Message>The difference between the request time and the current time is too large.</Message>
<RequestTime>Sat, 27 Dec 2014 11:47:05 GMT</RequestTime>
<ServerTime>2014-12-28T08:45:09Z</ServerTime>
<MaxAllowedSkewMilliseconds>900000</MaxAllowedSkewMilliseconds>
<RequestId>4189D5DAF2FA6649</RequestId>
<HostId>lBAhbNfeV4C7lHdjLwcTpVVH2snd/BW18hsZEQFkxqfgrmdD5pgAJJbAP6ULArRo</HostId>
</Error>
我的 docker 容器正在运行 Ubuntu 14.04...如果这有什么不同的话。 我也在使用 uWSGI 运行应用程序,没有 nginx 或 apache 或任何其他类型的反向代理服务器。
当文件被提供给站点时,我也会在运行时收到错误。
尝试的解决方案
其他 * 问题使用 S3 报告了类似的错误(没有专门与 Docker 结合使用),他们说这个错误是当您的系统时钟不同步时引起的,可以通过运行来修复
sudo service ntp stop
sudo ntpd -gq
sudo service ntp start
所以我在我的 Dockerfile 中添加了以下内容,但它并没有解决问题。
RUN apt-get install -y ntp
RUN ntpd -gq
RUN service ntp start
我还尝试使用sudo ntpd -gq 在构建 docker 映像之前同步本地计算机上的时间,但这也不起作用。
Dockerfile
FROM ubuntu:14.04
# Get most recent apt-get
RUN apt-get -y update
# Install python and other tools
RUN apt-get install -y tar git curl nano wget dialog net-tools build-essential
RUN apt-get install -y python3 python3-dev python-distribute
RUN apt-get install -y nginx supervisor
# Get Python3 version of pip
RUN apt-get -y install python3-setuptools
RUN easy_install3 pip
# Update system clock so S3 does not get 403 Error
# NOT WORKING
#RUN apt-get install -y ntp
#RUN ntpd -gq
#RUN service ntp start
RUN pip install uwsgi
RUN apt-get -y install libxml2-dev libxslt1-dev
RUN apt-get install -y python-software-properties uwsgi-plugin-python3
# Install GEOS
RUN apt-get -y install binutils libproj-dev gdal-bin
# Install node.js
RUN apt-get install -y nodejs npm
# Install postgresql dependencies
RUN apt-get update && \
apt-get install -y postgresql libpq-dev && \
rm -rf /var/lib/apt/lists
# Install pylibmc dependencies
RUN apt-get update
RUN apt-get install -y libmemcached-dev zlib1g-dev libssl-dev
ADD . /home/docker/code
# Setup config files
RUN ln -s /home/docker/code/supervisor-app.conf /etc/supervisor/conf.d/
RUN pip install -r /home/docker/code/vitru/requirements.txt
# Create directory for logs
RUN mkdir -p /var/logs
# Set environment as staging
ENV env staging
# Run django commands
# python3.4 is at /usr/bin/python3.4, but which works too
RUN $(which python3.4) /home/docker/code/vitru/manage.py collectstatic --noinput
RUN $(which python3.4) /home/docker/code/vitru/manage.py syncdb --noinput
RUN $(which python3.4) /home/docker/code/vitru/manage.py makemigrations --noinput
RUN $(which python3.4) /home/docker/code/vitru/manage.py migrate --noinput
EXPOSE 8000
CMD ["supervisord", "-c", "/home/docker/code/supervisor-app.conf"]
【问题讨论】:
-
你在使用 boot2docker 吗?我遇到了时间问题,因为当您的计算机休眠时,boot2docker vm 的时钟会停止。
-
是的,我是。我会尝试重新启动 boot2docker
标签: django ubuntu amazon-web-services amazon-s3 docker