簡體   English   中英

無法構建Dockerfile - :不是目錄使用ADD命令時出錯

[英]Can't build Dockerfile -: Not a directory Error using ADD command

我正在嘗試為python / flask webapp創建一個dockerfile,並且盡管根據我讀過的內容進行了多次更改,仍然會遇到問題

我目前的Dockerfile如下:

FROM ubuntu:latest

#Update OS
RUN sed -i 's/# \(.*multiverse$\)/\1/g' /etc/apt/sources.list
RUN apt-get update
RUN apt-get -y upgrade

# Install Python
RUN apt-get install -y python-dev python-pip

# Add requirements.txt
ADD requirements.txt /webapp
ADD requirements.txt .

# Install uwsgi Python web server
RUN pip install uwsgi

# Install app requirements
RUN pip install -r requirements.txt

# Create app directory
ADD . /webapp

# Set the default directory for our environment
ENV HOME /webapp
WORKDIR /webapp

# Expose port 8000 for uwsgi
EXPOSE 8000


ENTRYPOINT ["uwsgi", "--http", "127.0.0.1:8000", "--module", "app:app", "--processes", "1", "--threads", "8"]
#ENTRYPOINT ["python"]
CMD ["app.py"]

嘗試使用命令sudo docker build -t imgcomparer .運行此sudo docker build -t imgcomparer .

給出錯誤:

Step 10/15 : ADD . /webapp
Error processing tar file(exit status 1): Error setting up pivot dir: mkdir /var/lib/docker/aufs/mnt/53420471c832e61b7f75ac5fc5268d64b932a4d589a8464c63bf5868f127ff04/webapp/.pivot_root981494252: not a directory

經過一些研究,我發現在路徑的末尾放一個尾隨/可以工作(看這個問題這個 問題

這樣做(以下幾行相同)我在dockerfile中有以下內容:

# Create app directory
ADD . /webapp/

# Set the default directory for our environment
ENV HOME /webapp/
WORKDIR /webapp/

這給出了這個錯誤:

Step 10/15 : ADD . /webapp/
stat /var/lib/docker/aufs/mnt/f37b19a8d72d39cbbdfb0bae6359aee499fab0515e2415e251a50d528708bdd3/webapp/: not a directory

最后,我嘗試完全刪除有問題的行。 當我有

# Create app directory
# ADD . /webapp

# Set the default directory for our environment
ENV HOME /webapp
WORKDIR /webapp

docker文件成功構建! 但是,不出所料,嘗試運行它會產生錯誤:

sudo docker run -t imgcomparer

docker: Error response from daemon: oci runtime error: container_linux.go:247: starting container process caused "chdir to cwd (\"/webapp\") set in config.json failed: not a directory"
: Are you trying to mount a directory onto a file (or vice-versa)? Check if the specified host path exists and is the expected type.

目錄結構如下

app.py
image_data.db
README.txt
requirements.txt
Dockerfile
templates
 - index.html
static/
 - image.js
 - main.css
 img/
   - camera.png
 images/
   - empty

我相信你必須在引用它之前創建目錄:

RUN mkdir /webapp

編輯:

(在ADD requirements.txt /webapp之前)

ADD somefile.ext /folder

(沒有斜杠到文件夾)你引用一個文件,所以你在根目錄下得到一個名為folder ,其中包含somefile.ext的內容。 需要引用目錄和文件時要小心。

因此你也可以:

ADD requirements.txt /webapp/

另外:為什么要兩次添加requirements.txt 你應該在Dockerfile中盡可能地瞄准一些步驟,這樣你就可以:

[...]
RUN apt-get install -y python-dev python-pip && \
    pip install uwsgi
ADD . /webapp/
RUN pip install -r /webapp/requirements.txt
[...]

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM