不能build立Dockerfile – :不是目录错误使用ADD命令
我正在尝试为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
经过一番研究后,我发现把path尾端放在一边是可行的(见这个问题和这个 问题 )
这样做(和下面的行相同)我在我的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文件成功构build! 但是,毫不奇怪,试图运行它给出了一个错误:
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
我相信你必须在引用它之前创build目录:
RUN mkdir /webapp
编辑:
(在ADD requirements.txt /webapp
之前)
同
ADD somefile.ext /folder
(没有斜杠到文件夹)你引用一个文件,所以你得到一个名为folder
在根目录的文件,其中somefile.ext
的内容。 当你需要引用一个目录和一个文件的时候要小心。
因此你也可以:
ADD requirements.txt /webapp/
另外:为什么要添加requirements.txt
两次? 您应该尽可能在Dockerfile中尽可能less一些步骤,这样可以:
[...] RUN apt-get install -y python-dev python-pip && \ pip install uwsgi ADD . /webapp/ RUN pip install -r /webapp/requirements.txt [...]