Skip to content

Antek74/Django-to-do-docker

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

42 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Django-to-do

A dead simple Django ToDo Web App

This is a sample project that a novice django developer can use to get started.

Working

Django to do

Features

  • Dead simple
  • Easily add, delete
  • Simple UI
  • Blazing fast

Run the app

  • Make sure you have installed Docker daemon

  • Download the files from this repo

    $ git clone https://github.com/Antek74/Django-to-do-docker
  • Change the directory to the folder where you downloaded files

    $ cd Django-to-do-docker
  • Copy sqlite db to be externally hosted as volume (so it survives container restarts)

    $ cp ~/db-zadatak1.sqlite3 .
  • Build a Docker image

    $ sudo docker build -t django-to-do-docker .
  • Run the image

    $ sudo docker run \
    -d \
    --name django-to-do-docker \
    --mount type=bind,source="$(pwd)"/db-zadatak1.sqlite3,target=/code/todo/db.sqlite3 \
    -p 8000:8000 \
    -t django-to-do-docker:latest
  • After successful installation execute the following commands to check if container is running well:

    $ sudo docker ps
    >CONTAINER ID   IMAGE                        COMMAND                  CREATED         STATUS         PORTS                    NAMES
    >9a93c40b7de7   django-to-do-docker:latest   "python /code/todo/m…"   8 minutes ago   Up 8 minutes   0.0.0.0:8000->8000/tcp   django-to-do-docker
  • Visit $IP:8000 in your browser where $IP is IP address of the Docker host.

Dockerfile explanation

FROM python:3.7

  • app is built with Django 2.0.8, so max version of python is 3.7

ENV PYTHONUNBUFFERED 1

  • force python to flush data to stdout instantly, prevents buffering

RUN mkdir /code

  • mkdir the root dir

WORKDIR /code

  • define working dir

COPY requirements.txt /code/

  • copy requirements to working dir

RUN pip --no-cache-dir install -r requirements.txt

  • install python deps once

ADD . /code/

  • add all code to working dir

CMD [ "python", "/code/todo/manage.py", "runserver", "0.0.0.0:8000" ]

  • run server once container starts

Docker build syntax explanation

"-t"

  • defines name of the image

"."

  • defines working dir where to search for Dockerfile

Docker run syntax explanation

"-d"

  • detach, run it in the background

"--mount"

  • instruct container to bind external file (sqlite db) so it can persists across container restarts

"-p"

  • instructions for iptables so it can route the traffic from host to container ($host_port:$container_port)

    $ sudo iptables -t nat -L DOCKER -n
    >Chain DOCKER (2 references)
    >target     prot opt source               destination         
    >RETURN     all  --  0.0.0.0/0            0.0.0.0/0           
    >DNAT       tcp  --  0.0.0.0/0            0.0.0.0/0            tcp dpt:8000 to:172.17.0.2:8000

"-t"

  • define a name of the container

Built with ♥ by Omkar Pathak, dockerised by Ante K.

About

A simple Django to do web app

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 65.4%
  • HTML 32.2%
  • CSS 1.5%
  • Dockerfile 0.9%