Python Docker PermissionError:[Errno 13]权限被拒绝:';tmp&x27;

Python Docker PermissionError:[Errno 13]权限被拒绝:';tmp&x27;,python,docker,scrapy,dockerfile,Python,Docker,Scrapy,Dockerfile,我是docker的新手,已经构建了一个自定义容器来在我的云服务器上运行我的spider。我的scraper是使用Python3.6、Scrapy1.6和selenium构建的,并使用docker在一个容器中运行所有内容。启动spider时,我有一个scrapy open_spider方法,该方法在目录中运行另一个python脚本,该脚本生成了scrapy要爬网的URL。脚本将链接保存在一个文本文件中,但是,我获得了PermissionError:[Errno 13]权限被拒绝:“tmp 我已尝试

我是docker的新手,已经构建了一个自定义容器来在我的云服务器上运行我的spider。我的scraper是使用Python3.6、Scrapy1.6和selenium构建的,并使用docker在一个容器中运行所有内容。启动spider时,我有一个scrapy open_spider方法,该方法在目录中运行另一个python脚本,该脚本生成了scrapy要爬网的URL。脚本将链接保存在一个文本文件中,但是,我获得了PermissionError:[Errno 13]权限被拒绝:“tmp

我已尝试在tmp文件夹上运行chmod 777和a+rw,因此它将允许我创建文本文件,但我仍然收到权限拒绝错误。我已经研究了好几天,不知道如何解决这个问题

我笔记本电脑上的操作系统是ubuntu 18.04

下面是我的docker文件的链接

Dockerfile

FROM scrapinghub/scrapinghub-stack-scrapy:1.6-py3
RUN apt-get -y --no-install-recommends install zip unzip jq libxml2 libxml2-dev
RUN printf "deb http://archive.debian.org/debian/ jessie main\ndeb-src http://archive.debian.org/debian/ jessie main\ndeb http://security.debian.org jessie/updates main\ndeb-src http://security.debian.org jessie/updates main" > /etc/apt/sources.list


#============================================
# Google Chrome
#============================================
# can specify versions by CHROME_VERSION;
#  e.g. google-chrome-stable=53.0.2785.101-1
#       google-chrome-beta=53.0.2785.92-1
#       google-chrome-unstable=54.0.2840.14-1
#       latest (equivalent to google-chrome-stable)
#       google-chrome-beta  (pull latest beta)
#============================================
ARG CHROME_VERSION="google-chrome-stable"
RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - \
  && echo "deb http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list \
  && apt-get update -qqy \
  && apt-get -qqy install \
    ${CHROME_VERSION:-google-chrome-stable} \
  && rm /etc/apt/sources.list.d/google-chrome.list \
  && rm -rf /var/lib/apt/lists/* /var/cache/apt/*

#============================================
# Chrome Webdriver
#============================================
# can specify versions by CHROME_DRIVER_VERSION
# Latest released version will be used by default
#============================================
ARG CHROME_DRIVER_VERSION
RUN CHROME_STRING=$(google-chrome --version) \
  && CHROME_VERSION_STRING=$(echo "${CHROME_STRING}" | grep -oP "\d+\.\d+\.\d+\.\d+") \
  && CHROME_MAYOR_VERSION=$(echo "${CHROME_VERSION_STRING%%.*}") \
  && wget --no-verbose -O /tmp/LATEST_RELEASE "https://chromedriver.storage.googleapis.com/LATEST_RELEASE_${CHROME_MAYOR_VERSION}" \
  && CD_VERSION=$(cat "/tmp/LATEST_RELEASE") \
  && rm /tmp/LATEST_RELEASE \
  && if [ -z "$CHROME_DRIVER_VERSION" ]; \
     then CHROME_DRIVER_VERSION="${CD_VERSION}"; \
     fi \
  && CD_VERSION=$(echo $CHROME_DRIVER_VERSION) \
  && echo "Using chromedriver version: "$CD_VERSION \
  && wget --no-verbose -O /tmp/chromedriver_linux64.zip https://chromedriver.storage.googleapis.com/$CD_VERSION/chromedriver_linux64.zip \
  && rm -rf /opt/selenium/chromedriver \
  && unzip /tmp/chromedriver_linux64.zip -d /opt/selenium \
  && rm /tmp/chromedriver_linux64.zip \
  && mv /opt/selenium/chromedriver /opt/selenium/chromedriver-$CD_VERSION \
  && chmod 755 /opt/selenium/chromedriver-$CD_VERSION \
  && sudo ln -fs /opt/selenium/chromedriver-$CD_VERSION /usr/bin/chromedriver


#============================================
# crawlera-headless-proxy
#============================================

RUN curl -L https://github.com/scrapinghub/crawlera-headless-proxy/releases/download/1.1.1/crawlera-headless-proxy-linux-amd64 -o /usr/local/bin/crawlera-headless-proxy \
 && chmod +x /usr/local/bin/crawlera-headless-proxy
RUN chmod a+rw app/cars/spiders
RUN chmod a+rw app/cars/tmp
COPY ./start-crawl /usr/local/bin/start-crawl
ENV TERM xterm
ENV SCRAPY_SETTINGS_MODULE cars.settings
RUN pip install --upgrade pip
RUN mkdir -p /app
WORKDIR /app
COPY ./requirements.txt /app/requirements.txt
RUN pip install --no-cache-dir -r requirements.txt
COPY . /app
RUN python setup.py install
RUN chmod a+rw app/cars/tmp
这是指向我的setup.py文件的链接

#自动创建人:shub deploy
从setuptools导入设置中,查找\u包
设置(
命名为“汽车”,
version='1.0',
packages=find_packages(),
入口点={'scrapy':['settings=cars.settings']},
)

可能是第行的“setup.py”文件:

RUN python setup.py install

需要使用适当的权限执行吗?

将以下内容添加到Dockerfile中:

RUN adduser --disabled-login dockeruser
USER dockuser
RUN chown dockuser:dockuser -R /tmp/

注意:如果
--禁用的登录
也不起作用,请使用
--禁用的密码

或者更新您的Docker版本?您发布的Docker文件没有任何问题(我在我的机器上构建的),因此您没有使用Docker的权限,或者setup.py脚本中存在问题。如果你把它寄出去,我可以拍一张照片look@MicheleLambertucci我的猜测是我没有权限,但不是100%确定,因为我是docker的新手,并在云中部署它。这是指向my setup.py文件@dcarlo56ave的链接。请勿放置外部链接,因为它们可能会使您的问题对未来的读者毫无用处,从而破坏这些链接。把所有的代码放在你的question@eyllanesc对此很抱歉,我会这样做。当我运行时,我得到的选项d是不明确的(调试、禁用登录、禁用密码),我假设您的意思是--debug。感谢您的响应,但这仍然给出了一个错误。错误命令“/bin/sh-c chown dockuser:dockuser-R/tmp”返回非零代码:1:{'code':1,“message':“命令“/bin/sh-c chown dockuser:dockuser-R/tmp”返回非零代码:1”}错误:Docker操作失败chown:无法读取目录“/tmp/tmp.k7vv77Padw”:权限被拒绝chown:更改“/tmp/”的所有权:操作未被许可可能是,但如何执行