1

In my docker django project i need for read/write purpose to create a volumes in my Dockerile and install/run app on it.

i found this article : DockerFile on StackOverflow but sincerly i don't understand more about it.

Here my Dockerfile:

FROM python:3.6-alpine
EXPOSE 8000
RUN apk update
RUN apk add --no-cache make linux-headers libffi-dev jpeg-dev zlib-dev
RUN apk add postgresql-dev gcc python3-dev musl-dev
RUN mkdir /Code

VOLUME /var/lib/cathstudio/data
WORKDIR /Code

COPY ./requirements.txt .

RUN pip install --upgrade pip
RUN pip install -r requirements.txt
ENV PYTHONUNBUFFERED 1

COPY . /Code/

ENTRYPOINT python /Code/core/manage.py runserver 0.0.0.0:8000

at my original file i add the VOLUME /var/lib/cathstudio/data instruction, but after that how can i say to the rest of my code to use that volumes for WORKDIR, install requirements.txt, copy code and run app?

i don't what to specify it in RUN statement with -v directive after build, i would integrate the volume creation and manage directly in dockerfile.

So many thanks in advance

LinPy
  • 16,987
  • 4
  • 43
  • 57
Manuel Santi
  • 1,106
  • 17
  • 46
  • The Dockerfile you've shown looks correct, and is the normal way to use Docker. Why do you think you want the code in volumes? – David Maze Oct 28 '19 at 10:11

1 Answers1

1

for anything expect pip you may specify workdir once:

WORKDIR /var/lib/cathstudio/data

for pip use -t or --target:

pip install -t /var/lib/cathstudio/data

-t, --target

Install packages into <dir>. By default this will not replace existing files/folders in <dir>. Use --upgrade to replace existing

packages in with new versions

LinPy
  • 16,987
  • 4
  • 43
  • 57
  • thus RUN pip install -t /var/lib/cathstudio/data -r requirements.txt correct? thanks – Manuel Santi Oct 28 '19 at 06:37
  • and do not forget to set your PYTHONPATH to `/var/lib/cathstudio/data` so your code knows where to look for the installed modules – LinPy Oct 28 '19 at 06:53
  • In DockerFIle? i would to distribute my application for many people, i would automate mutch thinks possible – Manuel Santi Oct 28 '19 at 06:59
  • yes in docker file add ENV and ARG like so `ENV PYTHONPATH /var/lib/cathstudio/data` – LinPy Oct 28 '19 at 07:00
  • but i have to modify also ENTRYPOINT COPY or othe command with new path /var/lib/cathstudio/data? – Manuel Santi Oct 28 '19 at 07:30
  • ENTRYPOINT python /Code/core/manage.py runserver 0.0.0.0:8000 become ENTRYPOINT python /var/lib/cathstudio/data/manage.py runserver 0.0.0.0:8000 or just ENTRYPOINT python manage.py runserver 0.0.0.0:8000 ? So many thanks – Manuel Santi Oct 28 '19 at 07:51