Thinker
Thinker

Reputation: 5366

Django rest project dockerfile

I am absolutely new to docker. I have an existing Django Rest project whose structure looks like following:

enter image description here

My requirements.txt:

django==1.8.8
djangorestframework
markdown
django-filter
django-rest-auth       
django-cors-headers
django-secure
django-sslserver
django-rest-auth[extras]

Normally I create a virtual env > activate it > do pip install requirements.txt and additionally I need easy_install mysql-python to get started.

I want to dockerize this project. Can someone help me build a simple docker file this project?

Upvotes: 1

Views: 910

Answers (1)

John Moutafis
John Moutafis

Reputation: 23144

As @DriesDeRydt suggest in his comment, in the provided link there is a very simple example of a docker file which installs requirements:

Add the following content to the Dockerfile.

FROM python:2.7  
ENV PYTHONUNBUFFERED 1  
RUN mkdir /code  
WORKDIR /code  
ADD requirements.txt /code/  
RUN pip install -r requirements.txt 
ADD . /code/

This Dockerfile starts with a Python 2.7 base image. The base image is modified by adding a new code directory. The base image is further modified by installing the Python requirements defined in the requirements.txt file.

You can change the image to fit your needed python version, by pulling the needed python image. For example:

FROM python:2.7 change to FROM python:3.5 or FROM python:latest

But as the above Dockerfile stands and assuming that you will place it inside the server folder, it will work for a test case.

Here is the Dockerfile documentation for further reading.

Upvotes: 2

Related Questions