3

I am trying to make a dockerfile for a python/flask webapp and keep running into issues inspite of multiple changes based off what I've read

The Dockerfile I have at present is as follows:

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"]

Attempting to run this Dockerfile with the command sudo docker build -t imgcomparer .

gives the error:

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

After some research, I discovered that putting a trailing / at the end of the path would work (see this question and this one)

Upon doing that (and the same on the following lines) I have the following in my dockerfile:

# Create app directory
ADD . /webapp/

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

that gives this error:

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

Last, I tried removing the problematic line altogether. When I have

# Create app directory
# ADD . /webapp

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

The docker file successfully builds! But, unsurprisingly, trying to run it gives an error:

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.

Directory Structure is as follows

app.py
image_data.db
README.txt
requirements.txt
Dockerfile
templates
 - index.html
static/
 - image.js
 - main.css
 img/
   - camera.png
 images/
   - empty
6
  • Fiat you need to create the webapp directory, something like RUN mkdir /webapp Commented Apr 25, 2017 at 5:26
  • I put that immediately before the ADD command and it gives the error: mkdir: cannot create directory '/webapp/': File exists Commented Apr 25, 2017 at 5:29
  • I think the problem is that earlier you are using ADD requirements.txt /webapp, which is probably creating a file called webapp. Therefore, you can't then treat it as a directory Commented Apr 25, 2017 at 5:33
  • 1
    BTW, I don't think the python tag applies to this question Commented Apr 25, 2017 at 5:34
  • I added it to before the ADD requirements.txt line and now it builds... but it does not run! I get an error that imgcomparer unable to load configuration from app.py Commented Apr 25, 2017 at 5:39

1 Answer 1

2

I believe you have to create the directory before referencing to it:

RUN mkdir /webapp

edit:

(before ADD requirements.txt /webapp)

With

ADD somefile.ext /folder

(without trailing slash to the folder) you reference a file, so you get a file named folder at the root directory, with the contents of somefile.ext in it. Be careful when you need to reference a directory and when a file.

Thus you could also:

ADD requirements.txt /webapp/

Besides: why do you add requirements.txt twice? You should aim for a little steps as possible in a Dockerfile, so you could do:

[...]
RUN apt-get install -y python-dev python-pip && \
    pip install uwsgi
ADD . /webapp/
RUN pip install -r /webapp/requirements.txt
[...]
Sign up to request clarification or add additional context in comments.

5 Comments

Hmmm... That gives mkdir: cannot create directory '/webapp/': File exists The command '/bin/sh -c mkdir /webapp/' returned a non-zero code: 1 I put it immediately before the ADD line that is giving me trouble.
Did you put it BEFORE ADD requirements.txt /webapp?
Ah! I had it before ADD . /webapp Moving it further back made it properly build.... but (of course) it does not run. I get an error that imgcomparer unable to load configuration from app.py
I think that has nothing to do with Docker. See for example here: stackoverflow.com/questions/31164127/…
In fact you had to docker build --no-cache . in order to not use the cache and moving that instruction further back invalidated the cache :-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.