1

I have a Dockerfile

FROM ubuntu:xenial
LABEL maintainer="info@martin-thoma.com"

# Settings for the local user to create
ENV APP_USER docker
ENV APP_USER_UID 9999
ENV APP_USER_GROUP docker
ENV APP_USER_GROUP_GID 4711
ENV PYTHONIOENCODING utf-8

# Install and update software
RUN apt-get update -y && apt-get install -y --fix-missing git python-pip python-dev build-essential poppler-utils libmysqlclient-dev
RUN pip install pip --upgrade

# Copy projects code
COPY . /opt/app
WORKDIR /opt/app
RUN pip install -r requirements.txt

# Create user
RUN groupadd --gid ${APP_USER_GROUP_GID} ${APP_USER_GROUP} \
 && useradd --uid ${APP_USER_UID} --create-home -g ${APP_USER_GROUP} ${APP_USER} \
 && chown -R $APP_USER:$APP_USER_GROUP /opt/app

# Start app
USER docker
RUN mkdir -p /opt/app/filestorage
ENTRYPOINT ["python"]
CMD ["app.py"]

and a requirements.txt

-e git+https://github.com/ecederstrand/exchangelib.git@85eada6d59d0e2c757ef17c6ce143f3c976d2a90#egg=exchangelib
Flask==0.12.2
fuzzywuzzy==0.15.1

When I change the exchangelib line to exchangelib (hence not using git, but the version on PyPI) it works (but my code doesn't work as I need some of the recent changes).

When I have this, I get:

web_1  | ImportError: No module named exchangelib

What is the problem? Why can't my container find a pip installed package (via git)? How do I fix it?

My intuition is that the problem is that I install it as the root user, but the application runs as another user. The PyPI packages seem to get installed for all users while the editable is only local. But I still don't know how to fix it.

phd
  • 82,685
  • 13
  • 120
  • 165
Martin Thoma
  • 124,992
  • 159
  • 614
  • 958
  • Shot in the dark, but maybe it's related to this: https://stackoverflow.com/a/42982245/4557537 – Fadi Aug 16 '17 at 15:55
  • @Fadi I don't think so – Martin Thoma Aug 16 '17 at 15:56
  • If it helps, using your docker file etc, this works fine for me. – c3st7n Aug 16 '17 at 16:34
  • BTW, have you made sure that the `pip install ` step completes successfully? – Leon Aug 16 '17 at 16:36
  • @Leon I thought if `pip install` returns a non-zero exit code, then `docker-compose` would simply return an error? Besides this expectation, I didn't do any checks. – Martin Thoma Aug 16 '17 at 16:43
  • 1
    `-e` flag of `pip install` means *install in editable mode (i.e. setuptools "develop mode")* which is probably NOT what you really need. Try removing the `-e` switch from `requirements.txt`. – Leon Aug 16 '17 at 17:16

1 Answers1

1

Simply using

git+git://github.com/ecederstrand/exchangelib.git@85eada6d59d0e2c757ef17c6ce143f3c976d2a90#egg=exchangelib

as a line in the requirements.txt worked. No change in the docker file was necessary.

Martin Thoma
  • 124,992
  • 159
  • 614
  • 958